diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelType.java b/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelType.java index 6d1ff37d34..56d01dbaa8 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelType.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelType.java @@ -143,6 +143,7 @@ public boolean isMessage() { case TEXT: case VOICE: + case STAGE: case NEWS: case PRIVATE: case GROUP: diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/StageChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/StageChannel.java index 58f1b8de20..d981754c91 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/StageChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/StageChannel.java @@ -21,8 +21,11 @@ import net.dv8tion.jda.api.entities.GuildVoiceState; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.StageInstance; +import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel; +import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel; +import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer; import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; -import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel; import net.dv8tion.jda.api.exceptions.InsufficientPermissionException; import net.dv8tion.jda.api.managers.channel.concrete.StageChannelManager; @@ -42,8 +45,13 @@ * *

This is a specialized AudioChannel that can be used to host events with speakers and listeners. */ -public interface StageChannel extends GuildChannel, AudioChannel, StandardGuildChannel +public interface StageChannel extends StandardGuildChannel, GuildMessageChannel, AudioChannel, IWebhookContainer, IAgeRestrictedChannel, ISlowmodeChannel { + /** + * The maximum limit you can set with {@link StageChannelManager#setUserLimit(int)}. ({@value}) + */ + int MAX_USERLIMIT = 10000; + /** * {@link StageInstance} attached to this stage channel. * diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/VoiceChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/VoiceChannel.java index 6614e738ba..7c18c463b5 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/VoiceChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/VoiceChannel.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel; +import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel; import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer; import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; @@ -46,16 +47,12 @@ * @see JDA#getVoiceChannelsByName(String, boolean) * @see JDA#getVoiceChannelById(long) */ -public interface VoiceChannel extends AudioChannel, StandardGuildChannel, GuildMessageChannel, IWebhookContainer, IAgeRestrictedChannel +public interface VoiceChannel extends StandardGuildChannel, GuildMessageChannel, AudioChannel, IWebhookContainer, IAgeRestrictedChannel, ISlowmodeChannel { /** - * The maximum amount of {@link net.dv8tion.jda.api.entities.Member Members} that can be in this - * {@link VoiceChannel VoiceChannel} at once. - *
0 - No limit - * - * @return The maximum amount of members allowed in this channel at once. + * The maximum limit you can set with {@link VoiceChannelManager#setUserLimit(int)}. ({@value}) */ - int getUserLimit(); + int MAX_USERLIMIT = 99; @Nonnull @Override diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/AudioChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/AudioChannel.java index 3e3658746f..196059bb7e 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/AudioChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/middleman/AudioChannel.java @@ -62,6 +62,16 @@ public interface AudioChannel extends StandardGuildChannel */ int getBitrate(); + /** + * The maximum amount of {@link net.dv8tion.jda.api.entities.Member Members} that be in an audio connection within this channel concurrently. + *
Returns 0 if there is no limit. + * + *

Moderators with the {@link net.dv8tion.jda.api.Permission#VOICE_MOVE_OTHERS VOICE_MOVE_OTHERS} permission can bypass this limit. + * + * @return The maximum connections allowed in this channel concurrently + */ + int getUserLimit(); + /** * The {@link Region} of this channel. *
This will return {@link Region#AUTOMATIC} if the region of this channel is set to Automatic. diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/AudioChannelUnion.java b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/AudioChannelUnion.java index bef6ccc175..274fb98f21 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/AudioChannelUnion.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/AudioChannelUnion.java @@ -20,6 +20,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.StageChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import javax.annotation.Nonnull; @@ -79,4 +80,23 @@ public interface AudioChannelUnion extends AudioChannel */ @Nonnull StageChannel asStageChannel(); + + /** + * Casts this union to a {@link GuildMessageChannel}. + *
This method exists for developer discoverability. + * + *

Note: This is effectively equivalent to using the cast operator: + *

{@code
+     * //These are the same!
+     * GuildMessageChannel channel = union.asGuildMessageChannel();
+     * GuildMessageChannel channel2 = (GuildMessageChannel) union;
+     * }
+ * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link GuildMessageChannel}. + * + * @return The channel as a {@link GuildMessageChannel} + */ + @Nonnull + GuildMessageChannel asGuildMessageChannel(); } diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/GuildMessageChannelUnion.java b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/GuildMessageChannelUnion.java index 3dbb14503c..e3c7317182 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/GuildMessageChannelUnion.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/GuildMessageChannelUnion.java @@ -18,10 +18,8 @@ import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; -import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; -import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; @@ -38,6 +36,7 @@ *
  • {@link TextChannel}
  • *
  • {@link NewsChannel}
  • *
  • {@link VoiceChannel}
  • + *
  • {@link StageChannel}
  • *
  • {@link ThreadChannel}
  • * */ @@ -131,6 +130,28 @@ public interface GuildMessageChannelUnion extends GuildMessageChannel @Nonnull VoiceChannel asVoiceChannel(); + /** + * Casts this union to a {@link StageChannel}. + * This method exists for developer discoverability. + * + * Note: This is effectively equivalent to using the cast operator: + *
    
    +     * //These are the same!
    +     * StageChannel channel = union.asStageChannel();
    +     * StageChannel channel2 = (StageChannel) union;
    +     * 
    + * + * You can use {@link #getType()} to see if the channel is of type {@link ChannelType#STAGE} to validate + * whether you can call this method in addition to normal instanceof checks: channel instanceof StageChannel + * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link StageChannel}. + * + * @return The channel as a {@link StageChannel} + */ + @Nonnull + StageChannel asStageChannel(); + /** * Casts this union to a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer}. * This method exists for developer discoverability. @@ -149,6 +170,7 @@ public interface GuildMessageChannelUnion extends GuildMessageChannel * * @return The channel as a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer} */ + @Nonnull IThreadContainer asThreadContainer(); /** @@ -187,4 +209,25 @@ public interface GuildMessageChannelUnion extends GuildMessageChannel */ @Nonnull StandardGuildMessageChannel asStandardGuildMessageChannel(); + + /** + * Casts this union to a {@link AudioChannel}. + * This method exists for developer discoverability. + * + * Note: This is effectively equivalent to using the cast operator: + *
    
    +     * //These are the same!
    +     * AudioChannel channel = union.asAudioChannel();
    +     * AudioChannel channel2 = (AudioChannel) union;
    +     * 
    + * + * You can use channel instanceof AudioChannel to validate whether you can call this method. + * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link AudioChannel}. + * + * @return The channel as a {@link AudioChannel} + */ + @Nonnull + AudioChannel asAudioChannel(); } diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/IWebhookContainerUnion.java b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/IWebhookContainerUnion.java index 7715e494c1..2a6e92b6e9 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/IWebhookContainerUnion.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/IWebhookContainerUnion.java @@ -19,10 +19,8 @@ import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; import net.dv8tion.jda.api.entities.channel.attribute.IWebhookContainer; -import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; -import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; @@ -38,6 +36,8 @@ * */ @@ -152,6 +152,28 @@ public interface IWebhookContainerUnion extends IWebhookContainer @Nonnull VoiceChannel asVoiceChannel(); + /** + * Casts this union to a {@link StageChannel}. + * This method exists for developer discoverability. + * + * Note: This is effectively equivalent to using the cast operator: + *
    
    +     * //These are the same!
    +     * StageChannel channel = union.asStageChannel();
    +     * StageChannel channel2 = (StageChannel) union;
    +     * 
    + * + * You can use {@link #getType()} to see if the channel is of type {@link ChannelType#STAGE} to validate + * whether you can call this method in addition to normal instanceof checks: channel instanceof StageChannel + * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link StageChannel}. + * + * @return The channel as a {@link StageChannel} + */ + @Nonnull + StageChannel asStageChannel(); + /** * Casts this union to a {@link GuildMessageChannel}. *
    This works for the following channel types represented by this union: @@ -215,4 +237,25 @@ public interface IWebhookContainerUnion extends IWebhookContainer */ @Nonnull StandardGuildMessageChannel asStandardGuildMessageChannel(); + + /** + * Casts this union to a {@link AudioChannel}. + * This method exists for developer discoverability. + * + * Note: This is effectively equivalent to using the cast operator: + *
    
    +     * //These are the same!
    +     * AudioChannel channel = union.asAudioChannel();
    +     * AudioChannel channel2 = (AudioChannel) union;
    +     * 
    + * + * You can use channel instanceof AudioChannel to validate whether you can call this method. + * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link AudioChannel}. + * + * @return The channel as a {@link AudioChannel} + */ + @Nonnull + AudioChannel asAudioChannel(); } diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/MessageChannelUnion.java b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/MessageChannelUnion.java index faa2a08830..d559b038c8 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/MessageChannelUnion.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/MessageChannelUnion.java @@ -19,6 +19,7 @@ import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; @@ -34,6 +35,7 @@ *
  • {@link TextChannel}
  • *
  • {@link NewsChannel}
  • *
  • {@link VoiceChannel}
  • + *
  • {@link StageChannel}
  • *
  • {@link ThreadChannel}
  • *
  • {@link PrivateChannel}
  • * @@ -150,6 +152,28 @@ public interface MessageChannelUnion extends MessageChannel @Nonnull VoiceChannel asVoiceChannel(); + /** + * Casts this union to a {@link StageChannel}. + * This method exists for developer discoverability. + * + * Note: This is effectively equivalent to using the cast operator: + *
    
    +     * //These are the same!
    +     * StageChannel channel = union.asStageChannel();
    +     * StageChannel channel2 = (StageChannel) union;
    +     * 
    + * + * You can use {@link #getType()} to see if the channel is of type {@link ChannelType#STAGE} to validate + * whether you can call this method in addition to normal instanceof checks: channel instanceof StageChannel + * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link StageChannel}. + * + * @return The channel as a {@link StageChannel} + */ + @Nonnull + StageChannel asStageChannel(); + /** * Casts this union to a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer}. * This method exists for developer discoverability. @@ -197,4 +221,25 @@ public interface MessageChannelUnion extends MessageChannel */ @Nonnull GuildMessageChannel asGuildMessageChannel(); + + /** + * Casts this union to a {@link AudioChannel}. + * This method exists for developer discoverability. + * + * Note: This is effectively equivalent to using the cast operator: + *
    
    +     * //These are the same!
    +     * AudioChannel channel = union.asAudioChannel();
    +     * AudioChannel channel2 = (AudioChannel) union;
    +     * 
    + * + * You can use channel instanceof AudioChannel to validate whether you can call this method. + * + * @throws IllegalStateException + * If the channel represented by this union is not actually a {@link AudioChannel}. + * + * @return The channel as a {@link AudioChannel} + */ + @Nonnull + AudioChannel asAudioChannel(); } diff --git a/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/StageChannelManager.java b/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/StageChannelManager.java index 23a5c3c28e..ab279c69b3 100644 --- a/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/StageChannelManager.java +++ b/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/StageChannelManager.java @@ -17,6 +17,8 @@ package net.dv8tion.jda.api.managers.channel.concrete; import net.dv8tion.jda.api.entities.channel.concrete.StageChannel; +import net.dv8tion.jda.api.managers.channel.attribute.IAgeRestrictedChannelManager; +import net.dv8tion.jda.api.managers.channel.attribute.ISlowmodeChannelManager; import net.dv8tion.jda.api.managers.channel.middleman.AudioChannelManager; import net.dv8tion.jda.api.managers.channel.middleman.StandardGuildChannelManager; @@ -32,6 +34,8 @@ */ public interface StageChannelManager extends AudioChannelManager, - StandardGuildChannelManager + StandardGuildChannelManager, + IAgeRestrictedChannelManager, + ISlowmodeChannelManager { } diff --git a/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/VoiceChannelManager.java b/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/VoiceChannelManager.java index 9cb322eadd..29dcda78f4 100644 --- a/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/VoiceChannelManager.java +++ b/src/main/java/net/dv8tion/jda/api/managers/channel/concrete/VoiceChannelManager.java @@ -16,40 +16,17 @@ package net.dv8tion.jda.api.managers.channel.concrete; -import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; -import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.managers.channel.attribute.IAgeRestrictedChannelManager; +import net.dv8tion.jda.api.managers.channel.attribute.ISlowmodeChannelManager; import net.dv8tion.jda.api.managers.channel.middleman.AudioChannelManager; import net.dv8tion.jda.api.managers.channel.middleman.StandardGuildChannelManager; -import javax.annotation.CheckReturnValue; -import javax.annotation.Nonnull; - //TODO-v5: Docs public interface VoiceChannelManager extends AudioChannelManager, StandardGuildChannelManager, - IAgeRestrictedChannelManager + IAgeRestrictedChannelManager, + ISlowmodeChannelManager { - /** - * Sets the user-limit of the selected {@link VoiceChannel VoiceChannel}. - *
    Provide {@code 0} to reset the user-limit of the {@link VoiceChannel VoiceChannel} - * - *

    A channel user-limit must not be negative nor greater than {@code 99}! - *
    This is only available to {@link VoiceChannel VoiceChannels} - * - * @param userLimit - * The new user-limit for the selected {@link VoiceChannel VoiceChannel} - * - * @throws IllegalStateException - * If the selected {@link GuildChannel GuildChannel}'s type is not {@link ChannelType#VOICE VOICE} - * @throws IllegalArgumentException - * If the provided user-limit is negative or greater than {@code 99} - * - * @return ChannelManager for chaining convenience - */ - @Nonnull - @CheckReturnValue - VoiceChannelManager setUserLimit(int userLimit); } diff --git a/src/main/java/net/dv8tion/jda/api/managers/channel/middleman/AudioChannelManager.java b/src/main/java/net/dv8tion/jda/api/managers/channel/middleman/AudioChannelManager.java index 351294f54d..dd4887b112 100644 --- a/src/main/java/net/dv8tion/jda/api/managers/channel/middleman/AudioChannelManager.java +++ b/src/main/java/net/dv8tion/jda/api/managers/channel/middleman/AudioChannelManager.java @@ -18,7 +18,7 @@ import net.dv8tion.jda.api.Region; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.entities.channel.concrete.StageChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; @@ -29,17 +29,17 @@ public interface AudioChannelManager> extends StandardGuildChannelManager { /** - * Sets the bitrate of the selected {@link VoiceChannel VoiceChannel}. + * Sets the bitrate of the selected {@link AudioChannel}. *
    The default value is {@code 64000} * *

    A channel bitrate must not be less than {@code 8000} nor greater than {@link Guild#getMaxBitrate()}! - *
    This is only available to {@link VoiceChannel VoiceChannels} + *
    This is only available to {@link AudioChannel AudioChannels} * * @param bitrate - * The new bitrate for the selected {@link VoiceChannel VoiceChannel} + * The new bitrate for the selected {@link AudioChannel} * * @throws IllegalStateException - * If the selected {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel GuildChannel}'s type is not {@link ChannelType#VOICE VOICE} + * If the selected channel is not an {@link AudioChannel} * @throws IllegalArgumentException * If the provided bitrate is less than 8000 or greater than {@link Guild#getMaxBitrate()}. * @@ -52,7 +52,29 @@ public interface AudioChannelManageruser-limit of the selected {@link AudioChannel}. + *
    Provide {@code 0} to reset the user-limit of the {@link AudioChannel} + * + *

    A channel user-limit must not be negative nor greater than {@value VoiceChannel#MAX_USERLIMIT} for {@link VoiceChannel} + * and not greater than {@value StageChannel#MAX_USERLIMIT} for {@link StageChannel}! + *
    This is only available to {@link AudioChannel AudioChannels} + * + * @param userLimit + * The new user-limit for the selected {@link AudioChannel} + * + * @throws IllegalStateException + * If the selected channel is not an {@link AudioChannel} + * @throws IllegalArgumentException + * If the provided user-limit is negative or greater than the permitted maximum + * + * @return ChannelManager for chaining convenience + */ + @Nonnull + @CheckReturnValue + M setUserLimit(int userLimit); + + /** + * Sets the {@link Region Region} of the selected {@link AudioChannel}. *
    The default value is {@link Region#AUTOMATIC} * * Possible values are: @@ -72,14 +94,16 @@ public interface AudioChannelManager{@link Region#RUSSIA} * * - *
    This is only available to {@link VoiceChannel VoiceChannels}! + *
    This is only available to {@link AudioChannel AudioChannels}! * * @param region * The new {@link Region Region} + * * @throws IllegalStateException - * If the selected {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel GuildChannel}'s type is not {@link ChannelType#VOICE VOICE} + * If the selected channel is not an {@link AudioChannel} * @throws IllegalArgumentException * If the provided Region is not in the list of usable values + * * @return ChannelManager for chaining convenience */ @Nonnull diff --git a/src/main/java/net/dv8tion/jda/api/requests/restaction/ChannelAction.java b/src/main/java/net/dv8tion/jda/api/requests/restaction/ChannelAction.java index eea0519b44..86d7504aa5 100644 --- a/src/main/java/net/dv8tion/jda/api/requests/restaction/ChannelAction.java +++ b/src/main/java/net/dv8tion/jda/api/requests/restaction/ChannelAction.java @@ -27,8 +27,11 @@ import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel; import net.dv8tion.jda.api.entities.channel.concrete.Category; import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; +import net.dv8tion.jda.api.entities.channel.concrete.StageChannel; +import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.entities.channel.forums.BaseForumTag; import net.dv8tion.jda.api.entities.channel.forums.ForumTagData; +import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; @@ -585,15 +588,20 @@ default ChannelAction removePermissionOverride(@Nonnull IPermissionHolder hol ChannelAction setBitrate(@Nullable Integer bitrate); /** - * Sets the userlimit for the new VoiceChannel + * Sets the userlimit for the new {@link AudioChannel}. + *
    The limit maximum varies by type. + *

      + *
    • {@link ChannelType#VOICE} - {@value VoiceChannel#MAX_USERLIMIT}
    • + *
    • {@link ChannelType#STAGE} - {@value StageChannel#MAX_USERLIMIT}
    • + *
    * * @param userlimit - * The userlimit for the new VoiceChannel or {@code null}/{@code 0} to use no limit, + * The userlimit for the new AudioChannel or {@code null}/{@code 0} to use no limit * * @throws UnsupportedOperationException - * If this ChannelAction is not for a VoiceChannel + * If this ChannelAction is not for a AudioChannel * @throws IllegalArgumentException - * If the provided userlimit is negative or above {@code 99} + * If the provided userlimit is negative or above the permitted limit * * @return The current ChannelAction, for chaining convenience */ diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index b21882ceca..dee8de93e5 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1199,7 +1199,9 @@ public VoiceChannel createVoiceChannel(GuildImpl guild, DataObject json, long gu .setUserLimit(json.getInt("user_limit")) .setNSFW(json.getBoolean("nsfw")) .setBitrate(json.getInt("bitrate")) - .setRegion(json.getString("rtc_region", null)); + .setRegion(json.getString("rtc_region", null)) +// .setDefaultThreadSlowmode(json.getInt("default_thread_rate_limit_per_user", 0)) + .setSlowmode(json.getInt("rate_limit_per_user", 0)); createOverridesPass(channel, json.getArray("permission_overwrites")); if (playbackCache) @@ -1236,10 +1238,15 @@ public StageChannel createStageChannel(GuildImpl guild, DataObject json, long gu channel .setParentCategory(json.getLong("parent_id", 0)) + .setLatestMessageIdLong(json.getLong("last_message_id", 0)) .setName(json.getString("name")) .setPosition(json.getInt("position")) .setBitrate(json.getInt("bitrate")) - .setRegion(json.getString("rtc_region", null)); + .setUserLimit(json.getInt("user_limit", 0)) + .setNSFW(json.getBoolean("nsfw")) + .setRegion(json.getString("rtc_region", null)) +// .setDefaultThreadSlowmode(json.getInt("default_thread_rate_limit_per_user", 0)) + .setSlowmode(json.getInt("rate_limit_per_user", 0)); createOverridesPass(channel, json.getArray("permission_overwrites")); if (playbackCache) diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/StageChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/StageChannelImpl.java index 6d8f1cb202..9e6054820a 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/StageChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/StageChannelImpl.java @@ -35,7 +35,11 @@ import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.entities.GuildImpl; import net.dv8tion.jda.internal.entities.channel.middleman.AbstractStandardGuildChannelImpl; +import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IAgeRestrictedChannelMixin; +import net.dv8tion.jda.internal.entities.channel.mixin.attribute.ISlowmodeChannelMixin; +import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IWebhookContainerMixin; import net.dv8tion.jda.internal.entities.channel.mixin.middleman.AudioChannelMixin; +import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildMessageChannelMixin; import net.dv8tion.jda.internal.managers.channel.concrete.StageChannelManagerImpl; import net.dv8tion.jda.internal.requests.RestActionImpl; import net.dv8tion.jda.internal.requests.Route; @@ -52,13 +56,21 @@ public class StageChannelImpl extends AbstractStandardGuildChannelImpl implements StageChannel, - AudioChannelMixin + AudioChannelMixin, + GuildMessageChannelMixin, + IWebhookContainerMixin, + IAgeRestrictedChannelMixin, + ISlowmodeChannelMixin { private final TLongObjectMap connectedMembers = MiscUtil.newLongMap(); private StageInstance instance; private String region; private int bitrate; + private int userlimit; + private int slowmode; + private boolean ageRestricted; + private long latestMessageId; public StageChannelImpl(long id, GuildImpl guild) { @@ -78,6 +90,12 @@ public int getBitrate() return bitrate; } + @Override + public int getUserLimit() + { + return userlimit; + } + @Nullable @Override public String getRegionRaw() @@ -143,6 +161,31 @@ public ChannelAction createCopy(@Nonnull Guild guild) return action; } + @Override + public int getSlowmode() + { + return slowmode; + } + + @Override + public boolean isNSFW() + { + return ageRestricted; + } + + @Override + public boolean canTalk(@Nonnull Member member) + { + Checks.notNull(member, "Member"); + return member.hasPermission(this, Permission.MESSAGE_SEND); + } + + @Override + public long getLatestMessageIdLong() + { + return latestMessageId; + } + @Nonnull @Override public StageChannelManager getManager() @@ -197,6 +240,13 @@ public StageChannelImpl setBitrate(int bitrate) return this; } + @Override + public StageChannelImpl setUserLimit(int userlimit) + { + this.userlimit = userlimit; + return this; + } + @Override public StageChannelImpl setRegion(String region) { @@ -210,6 +260,27 @@ public StageChannelImpl setStageInstance(StageInstance instance) return this; } + @Override + public StageChannelImpl setNSFW(boolean ageRestricted) + { + this.ageRestricted = ageRestricted; + return this; + } + + @Override + public StageChannelImpl setSlowmode(int slowmode) + { + this.slowmode = slowmode; + return this; + } + + @Override + public StageChannelImpl setLatestMessageIdLong(long latestMessageId) + { + this.latestMessageId = latestMessageId; + return this; + } + // -- Abstract Hooks -- @Override protected void onPositionChange() diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/VoiceChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/VoiceChannelImpl.java index 9564a3cc71..a9f3148599 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/VoiceChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/VoiceChannelImpl.java @@ -31,6 +31,7 @@ import net.dv8tion.jda.internal.entities.GuildImpl; import net.dv8tion.jda.internal.entities.channel.middleman.AbstractStandardGuildChannelImpl; import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IAgeRestrictedChannelMixin; +import net.dv8tion.jda.internal.entities.channel.mixin.attribute.ISlowmodeChannelMixin; import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IWebhookContainerMixin; import net.dv8tion.jda.internal.entities.channel.mixin.middleman.AudioChannelMixin; import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildMessageChannelMixin; @@ -48,7 +49,8 @@ public class VoiceChannelImpl extends AbstractStandardGuildChannelImpl, AudioChannelMixin, IWebhookContainerMixin, - IAgeRestrictedChannelMixin + IAgeRestrictedChannelMixin, + ISlowmodeChannelMixin { private final TLongObjectMap connectedMembers = MiscUtil.newLongMap(); @@ -56,6 +58,7 @@ public class VoiceChannelImpl extends AbstractStandardGuildChannelImpl> T setBitrate(int bitrate); + T setUserLimit(int userlimit); + T setRegion(String region); } diff --git a/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java index bcad8b553f..842cc20218 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java @@ -48,7 +48,6 @@ import net.dv8tion.jda.internal.entities.*; import net.dv8tion.jda.internal.entities.channel.concrete.NewsChannelImpl; import net.dv8tion.jda.internal.entities.channel.concrete.TextChannelImpl; -import net.dv8tion.jda.internal.entities.channel.concrete.VoiceChannelImpl; import net.dv8tion.jda.internal.entities.channel.middleman.AbstractGuildChannelImpl; import net.dv8tion.jda.internal.entities.channel.mixin.attribute.*; import net.dv8tion.jda.internal.entities.channel.mixin.middleman.AudioChannelMixin; @@ -190,19 +189,6 @@ protected Long handleInternally(DataObject content) } break; case VOICE: - VoiceChannelImpl voiceChannel = (VoiceChannelImpl) channel; - - int userLimit = content.getInt("user_limit"); - int oldLimit = voiceChannel.getUserLimit(); - if (oldLimit != userLimit) - { - voiceChannel.setUserLimit(userLimit); - getJDA().handleEvent( - new ChannelUpdateUserLimitEvent( - getJDA(), responseNumber, - voiceChannel, oldLimit, userLimit)); - } - break; case TEXT: case NEWS: case STAGE: @@ -562,6 +548,18 @@ private void handleAudioChannel(AudioChannelMixin channel, DataObject content channel, oldBitrate, bitrate)); } + int userLimit = content.getInt("user_limit"); + int oldLimit = channel.getUserLimit(); + + if (oldLimit != userLimit) + { + channel.setUserLimit(userLimit); + getJDA().handleEvent( + new ChannelUpdateUserLimitEvent( + getJDA(), responseNumber, + channel, oldLimit, userLimit)); + } + String oldRegion = channel.getRegionRaw(); String regionRaw = content.getString("rtc_region", null); diff --git a/src/main/java/net/dv8tion/jda/internal/managers/channel/ChannelManagerImpl.java b/src/main/java/net/dv8tion/jda/internal/managers/channel/ChannelManagerImpl.java index 0670b28256..f224e0633a 100644 --- a/src/main/java/net/dv8tion/jda/internal/managers/channel/ChannelManagerImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/managers/channel/ChannelManagerImpl.java @@ -27,9 +27,7 @@ import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.attribute.IPermissionContainer; import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel; -import net.dv8tion.jda.api.entities.channel.concrete.Category; -import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; -import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.entities.channel.forums.BaseForumTag; import net.dv8tion.jda.api.entities.channel.forums.ForumTagSnowflake; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; @@ -491,10 +489,13 @@ public M setSlowmode(int slowmode) @CheckReturnValue public M setUserLimit(int userLimit) { - if (type != ChannelType.VOICE) - throw new IllegalStateException("Can only set userlimit on voice channels"); Checks.notNegative(userLimit, "Userlimit"); - Checks.check(userLimit <= 99, "Userlimit may not be greater than 99"); + if (type == ChannelType.VOICE) + Checks.check(userLimit <= VoiceChannel.MAX_USERLIMIT, "Userlimit may not be greater than %d for voice channels", VoiceChannel.MAX_USERLIMIT); + else if (type == ChannelType.STAGE) + Checks.check(userLimit <= StageChannel.MAX_USERLIMIT, "Userlimit may not be greater than %d for stage channels", StageChannel.MAX_USERLIMIT); + else + throw new IllegalStateException("Can only set userlimit on audio channels"); this.userlimit = userLimit; set |= USERLIMIT; return (M) this; diff --git a/src/main/java/net/dv8tion/jda/internal/requests/restaction/ChannelActionImpl.java b/src/main/java/net/dv8tion/jda/internal/requests/restaction/ChannelActionImpl.java index 692eb1445b..edbd5eb5bc 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/restaction/ChannelActionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/restaction/ChannelActionImpl.java @@ -27,6 +27,8 @@ import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel; import net.dv8tion.jda.api.entities.channel.concrete.Category; import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; +import net.dv8tion.jda.api.entities.channel.concrete.StageChannel; +import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.entities.channel.forums.BaseForumTag; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; @@ -370,10 +372,16 @@ else if (bitrate > maxBitrate) @CheckReturnValue public ChannelActionImpl setUserlimit(Integer userlimit) { - if (type != ChannelType.VOICE) - throw new UnsupportedOperationException("Can only set the userlimit for a VoiceChannel!"); - if (userlimit != null && (userlimit < 0 || userlimit > 99)) - throw new IllegalArgumentException("Userlimit must be between 0-99!"); + if (userlimit != null) + { + Checks.notNegative(userlimit, "Userlimit"); + if (type == ChannelType.VOICE) + Checks.check(userlimit <= VoiceChannel.MAX_USERLIMIT, "Userlimit may not be greater than %d for voice channels", VoiceChannel.MAX_USERLIMIT); + else if (type == ChannelType.STAGE) + Checks.check(userlimit <= StageChannel.MAX_USERLIMIT, "Userlimit may not be greater than %d for stage channels", StageChannel.MAX_USERLIMIT); + else + throw new IllegalStateException("Can only set userlimit on audio channels"); + } this.userlimit = userlimit; return this; }