From cf00f6c93741284a1110882b567c5bfc274b0a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Spie=C3=9F?= Date: Sun, 7 Jul 2024 17:44:50 +0200 Subject: [PATCH] Update and remove deprecated symbols (#2686) --- src/main/java/net/dv8tion/jda/api/JDA.java | 16 +- .../java/net/dv8tion/jda/api/JDABuilder.java | 90 +----- .../api/audio/hooks/ConnectionListener.java | 109 +------ .../jda/api/audio/hooks/ListenerProxy.java | 23 -- .../net/dv8tion/jda/api/audit/ActionType.java | 4 +- .../dv8tion/jda/api/audit/AuditLogKey.java | 16 - .../net/dv8tion/jda/api/entities/Guild.java | 12 - .../net/dv8tion/jda/api/entities/Member.java | 47 --- .../net/dv8tion/jda/api/entities/Message.java | 279 +----------------- .../jda/api/entities/MessageEmbed.java | 15 - .../jda/api/entities/StageInstance.java | 11 - .../net/dv8tion/jda/api/entities/User.java | 22 +- .../self/SelfUpdateDiscriminatorEvent.java | 7 - .../update/UserUpdateDiscriminatorEvent.java | 7 - .../jda/api/hooks/ListenerAdapter.java | 9 +- .../jda/api/interactions/modals/Modal.java | 91 ------ .../jda/api/managers/AccountManager.java | 15 +- .../jda/api/managers/AudioManager.java | 22 -- .../api/managers/StageInstanceManager.java | 9 +- .../jda/api/requests/GatewayIntent.java | 11 - .../jda/api/requests/RestRateLimiter.java | 14 - .../restaction/StageInstanceAction.java | 9 +- .../sharding/DefaultShardManagerBuilder.java | 124 +------- .../jda/api/utils/SessionController.java | 99 +------ .../jda/internal/audio/AudioWebSocket.java | 2 - .../jda/internal/entities/UserImpl.java | 2 +- .../internal/handle/UserUpdateHandler.java | 11 + .../internal/managers/AccountManagerImpl.java | 7 - .../internal/managers/AudioManagerImpl.java | 6 - .../managers/StageInstanceManagerImpl.java | 3 +- .../restaction/StageInstanceActionImpl.java | 3 +- .../EventConsistencyComplianceTest.java | 5 +- 32 files changed, 56 insertions(+), 1044 deletions(-) diff --git a/src/main/java/net/dv8tion/jda/api/JDA.java b/src/main/java/net/dv8tion/jda/api/JDA.java index e5fb70beee..c4feeb5ba0 100644 --- a/src/main/java/net/dv8tion/jda/api/JDA.java +++ b/src/main/java/net/dv8tion/jda/api/JDA.java @@ -1026,6 +1026,8 @@ default User getUserById(long id) * *

This will only check cached users! * + *

To check users without discriminators, use {@code username#0000} instead. + * * @param tag * The Discord Tag in the format {@code Username#Discriminator} * @@ -1035,7 +1037,6 @@ default User getUserById(long id) * @return The {@link net.dv8tion.jda.api.entities.User} for the discord tag or null if no user has the provided tag */ @Nullable - @Incubating default User getUserByTag(@Nonnull String tag) { Checks.notNull(tag, "Tag"); @@ -1069,16 +1070,13 @@ default User getUserByTag(@Nonnull String tag) * @return The {@link net.dv8tion.jda.api.entities.User} for the discord tag or null if no user has the provided tag */ @Nullable - @Incubating - default User getUserByTag(@Nonnull String username, @Nonnull String discriminator) + default User getUserByTag(@Nonnull String username, @Nullable String discriminator) { - Checks.notNull(username, "Username"); - Checks.notNull(discriminator, "Discriminator"); - Checks.check(discriminator.length() == 4 && Helpers.isNumeric(discriminator), "Invalid format for discriminator!"); - int codePointLength = Helpers.codePointLength(username); - Checks.check(codePointLength >= 2 && codePointLength <= 32, "Username must be between 2 and 32 codepoints in length!"); + Checks.inRange(username, 2, 32, "Username"); + Checks.check(discriminator == null || discriminator.length() == 4 && Helpers.isNumeric(discriminator), "Invalid format for discriminator! Provided: %s", discriminator); + String actualDiscriminator = discriminator == null ? "0000" : discriminator; return getUserCache().applyStream(stream -> - stream.filter(it -> it.getDiscriminator().equals(discriminator)) + stream.filter(it -> it.getDiscriminator().equals(actualDiscriminator)) .filter(it -> it.getName().equals(username)) .findFirst() .orElse(null) diff --git a/src/main/java/net/dv8tion/jda/api/JDABuilder.java b/src/main/java/net/dv8tion/jda/api/JDABuilder.java index 170ee79607..deceb43870 100644 --- a/src/main/java/net/dv8tion/jda/api/JDABuilder.java +++ b/src/main/java/net/dv8tion/jda/api/JDABuilder.java @@ -16,8 +16,6 @@ package net.dv8tion.jda.api; import com.neovisionaries.ws.client.WebSocketFactory; -import net.dv8tion.jda.annotations.ForRemoval; -import net.dv8tion.jda.annotations.ReplaceWith; import net.dv8tion.jda.api.audio.factory.IAudioSendFactory; import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.events.Event; @@ -547,32 +545,6 @@ public JDABuilder setEventPassthrough(boolean enable) return setFlag(ConfigFlag.EVENT_PASSTHROUGH, enable); } - /** - * Whether the rate-limit should be relative to the current time plus latency. - *
By default we use the {@code X-RateLimit-Reset-After} header to determine when - * a rate-limit is no longer imminent. This has the disadvantage that it might wait longer than needed due - * to the latency which is ignored by the reset-after relative delay. - * - *

When disabled, we will use the {@code X-RateLimit-Reset} absolute timestamp instead which accounts for - * latency but requires a properly NTP synchronized clock to be present. - * If your system does have this feature you might gain a little quicker rate-limit handling than the default allows. - * - *

Default: true - * - * @param enable - * True, if the relative {@code X-RateLimit-Reset-After} header should be used. - * - * @return The JDABuilder instance. Useful for chaining. - */ - @Nonnull - @Deprecated - @ForRemoval(deadline = "5.1.0") - @ReplaceWith("setRestConfig(new RestConfig().setRelativeRateLimit(enable))") - public JDABuilder setRelativeRateLimit(boolean enable) - { - return setFlag(ConfigFlag.USE_RELATIVE_RATELIMIT, enable); - } - /** * Custom {@link RestConfig} to use for this JDA instance. *
This can be used to customize how rate-limits are handled and configure a custom http proxy. @@ -903,67 +875,7 @@ public JDABuilder setWebsocketFactory(@Nullable WebSocketFactory factory) * the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution * and should be handled carefully. Only change this pool if you know what you're doing. *
This automatically disables the automatic shutdown of the rate-limit pool, you can enable - * it using {@link #setRateLimitPool(ScheduledExecutorService, boolean) setRateLimitPool(executor, true)} - * - *

This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. - * Besides that it is also used by planned execution for {@link net.dv8tion.jda.api.requests.RestAction#queueAfter(long, TimeUnit)} - * and similar methods. - * - *

Default: {@link ScheduledThreadPoolExecutor} with 5 threads. - * - * @param pool - * The thread-pool to use for rate-limit handling - * - * @return The JDABuilder instance. Useful for chaining. - * - * @deprecated This pool is now split into two pools. - * You should use {@link #setRateLimitScheduler(ScheduledExecutorService)} and {@link #setRateLimitElastic(ExecutorService)} instead. - */ - @Nonnull - @Deprecated - @ReplaceWith("setRateLimitScheduler(pool)") - public JDABuilder setRateLimitPool(@Nullable ScheduledExecutorService pool) - { - return setRateLimitPool(pool, pool == null); - } - - /** - * Sets the {@link ScheduledExecutorService ScheduledExecutorService} that should be used in - * the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution - * and should be handled carefully. Only change this pool if you know what you're doing. - * - *

This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. - * Besides that it is also used by planned execution for {@link net.dv8tion.jda.api.requests.RestAction#queueAfter(long, TimeUnit)} - * and similar methods. - * - *

Default: {@link ScheduledThreadPoolExecutor} with 5 threads. - * - * @param pool - * The thread-pool to use for rate-limit handling - * @param automaticShutdown - * Whether {@link JDA#shutdown()} should shutdown this pool - * - * @return The JDABuilder instance. Useful for chaining. - * - * @deprecated This pool is now split into two pools. - * You should use {@link #setRateLimitScheduler(ScheduledExecutorService, boolean)} and {@link #setRateLimitElastic(ExecutorService, boolean)} instead. - */ - @Nonnull - @Deprecated - @ReplaceWith("setRateLimitScheduler(pool, automaticShutdown)") - public JDABuilder setRateLimitPool(@Nullable ScheduledExecutorService pool, boolean automaticShutdown) - { - this.rateLimitScheduler = pool; - this.shutdownRateLimitScheduler = automaticShutdown; - return this; - } - - /** - * Sets the {@link ScheduledExecutorService ScheduledExecutorService} that should be used in - * the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution - * and should be handled carefully. Only change this pool if you know what you're doing. - *
This automatically disables the automatic shutdown of the rate-limit pool, you can enable - * it using {@link #setRateLimitPool(ScheduledExecutorService, boolean) setRateLimitPool(executor, true)} + * it using {@link #setRateLimitScheduler(ScheduledExecutorService, boolean) setRateLimitScheduler(executor, true)} * *

This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. * Besides that it is also used by planned execution for {@link net.dv8tion.jda.api.requests.RestAction#queueAfter(long, TimeUnit)} diff --git a/src/main/java/net/dv8tion/jda/api/audio/hooks/ConnectionListener.java b/src/main/java/net/dv8tion/jda/api/audio/hooks/ConnectionListener.java index 2c67861570..e76fa4bdff 100644 --- a/src/main/java/net/dv8tion/jda/api/audio/hooks/ConnectionListener.java +++ b/src/main/java/net/dv8tion/jda/api/audio/hooks/ConnectionListener.java @@ -16,8 +16,6 @@ package net.dv8tion.jda.api.audio.hooks; -import net.dv8tion.jda.annotations.ForRemoval; -import net.dv8tion.jda.annotations.ReplaceWith; import net.dv8tion.jda.api.audio.SpeakingMode; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.UserSnowflake; @@ -38,7 +36,7 @@ public interface ConnectionListener * @param ping * The time, in milliseconds, for round-trip packet travel to discord. */ - void onPing(long ping); + default void onPing(long ping) {} /** * Called when the status of the audio channel changes. Used to track the connection state of the audio connection @@ -47,110 +45,7 @@ public interface ConnectionListener * @param status * The new {@link net.dv8tion.jda.api.audio.hooks.ConnectionStatus ConnectionStatus} of the audio connection. */ - void onStatusChange(@Nonnull ConnectionStatus status); - - /** - * This method is an easy way to detect if a user is talking. Discord sends us an event when a user starts or stops - * talking and it is parallel to the audio socket, so this event could come milliseconds before or after audio begins - * or stops. This method is brilliant for clients wanting to display that a user is currently talking. - *

- * Unlike the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleCombinedAudio(net.dv8tion.jda.api.audio.CombinedAudio) - * AudioReceiveHandler.handleCombinedAudio(CombinedAudio)} and - * {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} methods which are - * fired extremely often, this method is fired as a flag for the beginning and ending of audio transmission, and as such - * is only fired when that changes. So while the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} method is fired every time JDA receives audio data from Discord, - * this is only fired when that stream starts and when it stops. - *
If the user speaks for 3 minutes straight without ever stopping, then this would fire 2 times, once at the beginning - * and once after 3 minutes when they stop talking even though the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} method was fired thousands of times over the course of the 3 minutes. - * - * @param user - * Never-null {@link net.dv8tion.jda.api.entities.User User} who's talking status has changed. - * @param speaking - * If true, the user has begun transmitting audio. - * - * @deprecated This method no longer represents the actual speaking state of the user. - * Discord does not send updates when a user starts and stops speaking anymore. - * You can use {@link #onUserSpeakingModeUpdate(UserSnowflake, EnumSet)} to see when a user changes their speaking mode, - * or use an {@link net.dv8tion.jda.api.audio.AudioReceiveHandler AudioReceiveHandler} to check when a user is speaking. - */ - @Deprecated - @ForRemoval - @ReplaceWith("onUserSpeakingModeUpdate(User, EnumSet)") - default void onUserSpeaking(@Nonnull User user, boolean speaking) {} - - /** - * This method is an easy way to detect if a user is talking. Discord sends us an event when a user starts or stops - * talking and it is parallel to the audio socket, so this event could come milliseconds before or after audio begins - * or stops. This method is brilliant for clients wanting to display that a user is currently talking. - *

- * Unlike the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleCombinedAudio(net.dv8tion.jda.api.audio.CombinedAudio) - * AudioReceiveHandler.handleCombinedAudio(CombinedAudio)} and - * {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} methods which are - * fired extremely often, this method is fired as a flag for the beginning and ending of audio transmission, and as such - * is only fired when that changes. So while the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} method is fired every time JDA receives audio data from Discord, - * this is only fired when that stream starts and when it stops. - *
If the user speaks for 3 minutes straight without ever stopping, then this would fire 2 times, once at the beginning - * and once after 3 minutes when they stop talking even though the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} method was fired thousands of times over the course of the 3 minutes. - * - * @param user - * Never-null {@link net.dv8tion.jda.api.entities.User User} who's talking status has changed. - * @param modes - * EnumSet, containing the active speaking modes. - * Empty if the user has stopped transmitting audio. - * - * @see java.util.EnumSet EnumSet - * @see net.dv8tion.jda.api.audio.SpeakingMode SpeakingMode - * - * @deprecated This method no longer represents the actual speaking state of the user. - * Discord does not send updates when a user starts and stops speaking anymore. - * You can use {@link #onUserSpeakingModeUpdate(UserSnowflake, EnumSet)} to see when a user changes their speaking mode, - * or use an {@link net.dv8tion.jda.api.audio.AudioReceiveHandler AudioReceiveHandler} to check when a user is speaking. - */ - @Deprecated - @ForRemoval - @ReplaceWith("onUserSpeakingModeUpdate(User, EnumSet)") - default void onUserSpeaking(@Nonnull User user, @Nonnull EnumSet modes) {} - - - /** - * This method is an easy way to detect if a user is talking. Discord sends us an event when a user starts or stops - * talking and it is parallel to the audio socket, so this event could come milliseconds before or after audio begins - * or stops. This method is brilliant for clients wanting to display that a user is currently talking. - *

- * Unlike the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleCombinedAudio(net.dv8tion.jda.api.audio.CombinedAudio) - * AudioReceiveHandler.handleCombinedAudio(CombinedAudio)} and - * {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} methods which are - * fired extremely often, this method is fired as a flag for the beginning and ending of audio transmission, and as such - * is only fired when that changes. So while the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} method is fired every time JDA receives audio data from Discord, - * this is only fired when that stream starts and when it stops. - *
If the user speaks for 3 minutes straight without ever stopping, then this would fire 2 times, once at the beginning - * and once after 3 minutes when they stop talking even though the {@link net.dv8tion.jda.api.audio.AudioReceiveHandler#handleUserAudio(net.dv8tion.jda.api.audio.UserAudio) - * AudioReceiveHandler.handleUserAudio(UserAudio)} method was fired thousands of times over the course of the 3 minutes. - * - * @param user - * Never-null {@link net.dv8tion.jda.api.entities.User User} who's talking status has changed. - * @param speaking - * If true, the user has begun transmitting audio. - * @param soundshare - * If true, the user is using soundshare - * - * @deprecated This method no longer represents the actual speaking state of the user. - * Discord does not send updates when a user starts and stops speaking anymore. - * You can use {@link #onUserSpeakingModeUpdate(UserSnowflake, EnumSet)} to see when a user changes their speaking mode, - * or use an {@link net.dv8tion.jda.api.audio.AudioReceiveHandler AudioReceiveHandler} to check when a user is speaking. - */ - @Deprecated - @ForRemoval - @ReplaceWith("onUserSpeakingModeUpdate(User, EnumSet)") - default void onUserSpeaking(@Nonnull User user, boolean speaking, boolean soundshare) {} + default void onStatusChange(@Nonnull ConnectionStatus status) {} /** * This method is used to listen for users changing their speaking mode. diff --git a/src/main/java/net/dv8tion/jda/api/audio/hooks/ListenerProxy.java b/src/main/java/net/dv8tion/jda/api/audio/hooks/ListenerProxy.java index 3872154b94..60d88588f3 100644 --- a/src/main/java/net/dv8tion/jda/api/audio/hooks/ListenerProxy.java +++ b/src/main/java/net/dv8tion/jda/api/audio/hooks/ListenerProxy.java @@ -71,29 +71,6 @@ public void onStatusChange(@Nonnull ConnectionStatus status) } } - @Override - public void onUserSpeaking(@Nonnull User user, @Nonnull EnumSet modes) - { - if (listener == null) - return; - ConnectionListener listener = this.listener; - try - { - if (listener != null) - { - listener.onUserSpeaking(user, modes); - listener.onUserSpeaking(user, modes.contains(SpeakingMode.VOICE)); - listener.onUserSpeaking(user, modes.contains(SpeakingMode.VOICE), modes.contains(SpeakingMode.SOUNDSHARE)); - } - } - catch (Throwable t) - { - log.error("The ConnectionListener encountered and uncaught exception", t); - if (t instanceof Error) - throw (Error) t; - } - } - @Override public void onUserSpeakingModeUpdate(@Nonnull UserSnowflake user, @Nonnull EnumSet modes) { diff --git a/src/main/java/net/dv8tion/jda/api/audit/ActionType.java b/src/main/java/net/dv8tion/jda/api/audit/ActionType.java index ba216cc69c..9c3bb1b052 100644 --- a/src/main/java/net/dv8tion/jda/api/audit/ActionType.java +++ b/src/main/java/net/dv8tion/jda/api/audit/ActionType.java @@ -551,7 +551,7 @@ public enum ActionType *

Possible Keys
*