diff --git a/src/main/java/net/dv8tion/jda/api/JDABuilder.java b/src/main/java/net/dv8tion/jda/api/JDABuilder.java index d28ce8255e..6aae036256 100644 --- a/src/main/java/net/dv8tion/jda/api/JDABuilder.java +++ b/src/main/java/net/dv8tion/jda/api/JDABuilder.java @@ -20,6 +20,7 @@ import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.events.Event; import net.dv8tion.jda.api.exceptions.InvalidTokenException; +import net.dv8tion.jda.api.events.session.ReadyEvent; import net.dv8tion.jda.api.hooks.IEventManager; import net.dv8tion.jda.api.hooks.VoiceDispatchInterceptor; import net.dv8tion.jda.api.requests.GatewayIntent; @@ -1738,7 +1739,7 @@ public JDABuilder setMaxBufferSize(int bufferSize) *
If you wish to be sure that the {@link net.dv8tion.jda.api.JDA} information is correct, please use
* {@link net.dv8tion.jda.api.JDA#awaitReady() JDA.awaitReady()} or register an
* {@link net.dv8tion.jda.api.hooks.EventListener EventListener} to listen for the
- * {@link net.dv8tion.jda.api.events.ReadyEvent ReadyEvent}.
+ * {@link ReadyEvent ReadyEvent}.
*
* @throws InvalidTokenException
* If the provided token is invalid.
diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/GuildReadyEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/GuildReadyEvent.java
index 006c5aa22b..fa5c123ab3 100644
--- a/src/main/java/net/dv8tion/jda/api/events/guild/GuildReadyEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/guild/GuildReadyEvent.java
@@ -18,16 +18,17 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
-import net.dv8tion.jda.api.events.ReadyEvent;
+import net.dv8tion.jda.api.events.session.ReadyEvent;
+import net.dv8tion.jda.api.events.session.SessionRecreateEvent;
import javax.annotation.Nonnull;
/**
- * Indicates that a {@link net.dv8tion.jda.api.entities.Guild Guild} finished setting up
+ * Indicates that a {@link Guild} finished setting up
*
This event is fired if a guild finished setting up during login phase.
* After this event is fired, JDA will start dispatching events related to this guild.
* This indicates a guild was created and added to the cache. It will be fired for both the initial
- * setup and full reconnects (indicated by {@link net.dv8tion.jda.api.events.ReconnectedEvent ReconnectedEvent}).
+ * setup and full reconnects (indicated by {@link SessionRecreateEvent}).
*
*
Can be used to initialize any services that depend on this guild.
*
@@ -35,7 +36,8 @@
* Guilds that fail to ready up will either timeout or get marked as unavailable.
*
You can use {@link ReadyEvent#getGuildUnavailableCount()} and {@link JDA#getUnavailableGuilds()} to check for unavailable guilds.
* {@link GuildTimeoutEvent} will be fired for guilds that don't ready up and also don't get marked as unavailable by Discord.
- * Guilds that timeout will be marked as unavailable by the timeout event, they will not fire a {@link GuildUnavailableEvent} as that event is only indicating that a guild becomes unavailable after ready happened.
+ * Guilds that timeout will be marked as unavailable by the timeout event,
+ * they will not fire a {@link GuildUnavailableEvent} as that event is only indicating that a guild becomes unavailable after ready happened.
*/
public class GuildReadyEvent extends GenericGuildEvent
{
diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/GuildTimeoutEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/GuildTimeoutEvent.java
index 14a359cdaf..ec01633c0a 100644
--- a/src/main/java/net/dv8tion/jda/api/events/guild/GuildTimeoutEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/guild/GuildTimeoutEvent.java
@@ -18,13 +18,13 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.events.Event;
-import net.dv8tion.jda.api.events.ReadyEvent;
+import net.dv8tion.jda.api.events.session.ReadyEvent;
import javax.annotation.Nonnull;
/**
* Indicates that a guild failed to ready up and timed out.
- *
Usually this event will be fired right before a {@link net.dv8tion.jda.api.events.ReadyEvent ReadyEvent}.
+ *
Usually this event will be fired right before a {@link ReadyEvent ReadyEvent}.
*
*
This will mark the guild as unavailable and it will not be usable when JDA becomes ready. * You can check all unavailable guilds with {@link ReadyEvent#getGuildUnavailableCount()} and {@link JDA#getUnavailableGuilds()}. diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GenericGuildVoiceUpdateEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/voice/GenericGuildVoiceUpdateEvent.java deleted file mode 100644 index ac0554b918..0000000000 --- a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GenericGuildVoiceUpdateEvent.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.dv8tion.jda.api.events.guild.voice; - -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; -import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - *
Requirements
- *
- *
These events require the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE VOICE_STATE} CacheFlag to be enabled, which requires
- * the {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} intent.
- *
- *
{@link net.dv8tion.jda.api.JDABuilder#createLight(String) createLight(String)} disables that CacheFlag by default!
- *
- *
Additionally, these events require the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} - * to cache the updated members. Discord does not specifically tell us about the updates, but merely tells us the - * member was updated and gives us the updated member object. In order to fire specific events like these we - * need to have the old member cached to compare against. - */ -public class GenericGuildVoiceUpdateEvent extends GenericGuildVoiceEvent implements GuildVoiceUpdateEvent -{ - protected final AudioChannel joined, left; - - public GenericGuildVoiceUpdateEvent( - @Nonnull JDA api, long responseNumber, @Nonnull Member member, @Nullable AudioChannel left, @Nullable AudioChannel joined) - { - super(api, responseNumber, member); - this.left = left; - this.joined = joined; - } - - @Nullable - @Override - public AudioChannelUnion getChannelLeft() - { - return (AudioChannelUnion) left; - } - - @Nullable - @Override - public AudioChannelUnion getChannelJoined() - { - return (AudioChannelUnion) joined; - } - - @Nonnull - @Override - public String getPropertyIdentifier() - { - return IDENTIFIER; - } - - @Nonnull - @Override - public Member getEntity() - { - return getMember(); - } - - @Nullable - @Override - public AudioChannel getOldValue() - { - return getChannelLeft(); - } - - @Nullable - @Override - public AudioChannel getNewValue() - { - return getChannelJoined(); - } - - @Override - public String toString() - { - return "MemberVoiceUpdate[" + getPropertyIdentifier() + "](" + getOldValue() + "->" + getNewValue() + ')'; - } -} diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceJoinEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceJoinEvent.java deleted file mode 100644 index 9f995b6425..0000000000 --- a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceJoinEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.dv8tion.jda.api.events.guild.voice; - -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; -import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; - -import javax.annotation.Nonnull; - -/** - * Indicates that a {@link net.dv8tion.jda.api.entities.Member Member} connected to a {@link net.dv8tion.jda.api.entities.channel.middleman.AudioChannel AudioChannel}. - * - *
When the {@link net.dv8tion.jda.api.entities.Member Member} is moved a {@link net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent GuildVoiceMoveEvent} is fired instead - * - *
Can be used to detect when a member joins a voice channel for the first time. - * - *
Requirements
- *
- *
This event requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE VOICE_STATE} CacheFlag to be enabled, which requires
- * the {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} intent.
- *
- *
{@link net.dv8tion.jda.api.JDABuilder#createLight(String) createLight(String)} disables that CacheFlag by default!
- *
- *
Additionally, this event requires the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} - * to cache the updated members. Discord does not specifically tell us about the updates, but merely tells us the - * member was updated and gives us the updated member object. In order to fire a specific event like this we - * need to have the old member cached to compare against. - */ -public class GuildVoiceJoinEvent extends GenericGuildVoiceUpdateEvent -{ - public GuildVoiceJoinEvent(@Nonnull JDA api, long responseNumber, @Nonnull Member member) - { - super(api, responseNumber, member, null, member.getVoiceState().getChannel()); - } - - @Nonnull - @Override - public AudioChannelUnion getChannelJoined() - { - return super.getChannelJoined(); - } - - @Nonnull - @Override - public AudioChannel getNewValue() - { - return super.getNewValue(); - } -} diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceLeaveEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceLeaveEvent.java deleted file mode 100644 index 89abed770c..0000000000 --- a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceLeaveEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.dv8tion.jda.api.events.guild.voice; - -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; -import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; - -import javax.annotation.Nonnull; - -/** - * Indicates that a {@link net.dv8tion.jda.api.entities.Member Member} disconnected from a {@link net.dv8tion.jda.api.entities.channel.middleman.AudioChannel AudioChannel}. - * - *
When the {@link net.dv8tion.jda.api.entities.Member Member} is moved a {@link net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent GuildVoiceMoveEvent} is fired instead - * - *
Can be used to detect when a member leaves a voice channel completely. - * - *
Requirements
- *
- *
This event requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE VOICE_STATE} CacheFlag to be enabled, which requires
- * the {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} intent.
- *
- *
{@link net.dv8tion.jda.api.JDABuilder#createLight(String) createLight(String)} disables that CacheFlag by default!
- *
- *
Additionally, this event requires the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} - * to cache the updated members. Discord does not specifically tell us about the updates, but merely tells us the - * member was updated and gives us the updated member object. In order to fire a specific event like this we - * need to have the old member cached to compare against. - * - * @see net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent GuildVoiceUpdateEvent - */ -public class GuildVoiceLeaveEvent extends GenericGuildVoiceUpdateEvent -{ - public GuildVoiceLeaveEvent(@Nonnull JDA api, long responseNumber, @Nonnull Member member, @Nonnull AudioChannel channelLeft) - { - super(api, responseNumber, member, channelLeft, null); - } - - @Nonnull - @Override - public AudioChannelUnion getChannelLeft() - { - return super.getChannelLeft(); - } - - @Nonnull - @Override - public AudioChannel getOldValue() - { - return super.getOldValue(); - } -} diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceMoveEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceMoveEvent.java deleted file mode 100644 index d2533678f4..0000000000 --- a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceMoveEvent.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.dv8tion.jda.api.events.guild.voice; - -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; -import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; - -import javax.annotation.Nonnull; - -/** - * Indicates that a {@link net.dv8tion.jda.api.entities.Member Member} moves between {@link net.dv8tion.jda.api.entities.channel.middleman.AudioChannel AudioChannels}. - * - *
When the {@link net.dv8tion.jda.api.entities.Member Member} is leaving a {@link net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent GuildVoiceLeaveEvent} is fired instead - * - *
Can be used to detect when a member moves from one voice channel to another in the same guild. - * - *
Requirements
- *
- *
This event requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE VOICE_STATE} CacheFlag to be enabled, which requires
- * the {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} intent.
- *
- *
{@link net.dv8tion.jda.api.JDABuilder#createLight(String) createLight(String)} disables that CacheFlag by default!
- *
- *
Additionally, this event requires the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy}
- * to cache the updated members. Discord does not specifically tell us about the updates, but merely tells us the
- * member was updated and gives us the updated member object. In order to fire a specific event like this we
- * need to have the old member cached to compare against.
- *
- * @see net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent GuildVoiceUpdateEvent
- */
-public class GuildVoiceMoveEvent extends GenericGuildVoiceUpdateEvent
-{
- public GuildVoiceMoveEvent(@Nonnull JDA api, long responseNumber, @Nonnull Member member, @Nonnull AudioChannel channelLeft)
- {
- super(api, responseNumber, member, channelLeft, member.getVoiceState().getChannel());
- }
-
- @Nonnull
- @Override
- public AudioChannelUnion getChannelLeft()
- {
- return super.getChannelLeft();
- }
-
- @Nonnull
- @Override
- public AudioChannelUnion getChannelJoined()
- {
- return super.getChannelJoined();
- }
-
- @Nonnull
- @Override
- public AudioChannel getOldValue()
- {
- return super.getOldValue();
- }
-
- @Nonnull
- @Override
- public AudioChannel getNewValue()
- {
- return super.getNewValue();
- }
-}
diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceUpdateEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceUpdateEvent.java
index b9d5561df8..db244128cb 100644
--- a/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceUpdateEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/guild/voice/GuildVoiceUpdateEvent.java
@@ -16,7 +16,7 @@
package net.dv8tion.jda.api.events.guild.voice;
-import net.dv8tion.jda.api.entities.Guild;
+import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
@@ -26,13 +26,8 @@
import javax.annotation.Nullable;
/**
- * Indicates that a {@link net.dv8tion.jda.api.entities.Member Member} joined or left an {@link net.dv8tion.jda.api.entities.channel.middleman.AudioChannel AudioChannel}.
- *
Generic event that combines
- * {@link net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent GuildVoiceLeaveEvent},
- * {@link net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent GuildVoiceJoinEvent}, and
- * {@link net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent GuildVoiceMoveEvent} for convenience.
- *
- *
Can be used to detect when a Member leaves/joins an AudioChannel + * Indicates that a {@link net.dv8tion.jda.api.entities.Member Member} joined or left an {@link AudioChannel}. + *
Can be used to detect when a Member leaves/joins an AudioChannel. * *
Requirements
*
@@ -46,27 +41,21 @@
* member was updated and gives us the updated member object. In order to fire a specific event like this we
* need to have the old member cached to compare against.
*
- *
Identifier: {@code voice-channel} + *
Identifier: {@code audio-channel}
*/
-public interface GuildVoiceUpdateEvent extends UpdateEvent This package contains all implementations of {@link net.dv8tion.jda.api.events.Event Event}.
* All events are forwarded by an {@link net.dv8tion.jda.api.hooks.IEventManager IEventManager} implementation.
- * This is primarily used to inform about the connection state and whether a resume happens.
+ */
+public abstract class GenericSessionEvent extends Event
+{
+ protected final SessionState state;
+
+ public GenericSessionEvent(@Nonnull JDA api, @Nonnull SessionState state)
+ {
+ super(api);
+ this.state = state;
+ }
+
+ /**
+ * The new session state.
+ *
+ * @return {@link SessionState}
+ */
+ @Nonnull
+ public SessionState getState()
+ {
+ return state;
+ }
+}
diff --git a/src/main/java/net/dv8tion/jda/api/events/ReadyEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/ReadyEvent.java
similarity index 94%
rename from src/main/java/net/dv8tion/jda/api/events/ReadyEvent.java
rename to src/main/java/net/dv8tion/jda/api/events/session/ReadyEvent.java
index e6bfad4e32..2eb6899d1f 100644
--- a/src/main/java/net/dv8tion/jda/api/events/ReadyEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/session/ReadyEvent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.dv8tion.jda.api.events;
+package net.dv8tion.jda.api.events.session;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.internal.JDAImpl;
@@ -28,14 +28,14 @@
* Can be used to indicate when JDA finished populating internal objects and is ready to be used.
* When this is fired all available entities are cached and accessible.
*/
-public class ReadyEvent extends Event
+public class ReadyEvent extends GenericSessionEvent
{
private final int availableGuilds;
private final int unavailableGuilds;
- public ReadyEvent(@Nonnull JDA api, long responseNumber)
+ public ReadyEvent(@Nonnull JDA api)
{
- super(api, responseNumber);
+ super(api, SessionState.READY);
this.availableGuilds = (int) getJDA().getGuildCache().size();
GuildSetupController setupController = ((JDAImpl) getJDA()).getGuildSetupController();
this.unavailableGuilds = setupController.getSetupNodes(GuildSetupController.Status.UNAVAILABLE).size() + setupController.getUnavailableGuilds().size();
diff --git a/src/main/java/net/dv8tion/jda/api/events/DisconnectEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/SessionDisconnectEvent.java
similarity index 91%
rename from src/main/java/net/dv8tion/jda/api/events/DisconnectEvent.java
rename to src/main/java/net/dv8tion/jda/api/events/session/SessionDisconnectEvent.java
index 80b9137a26..fb7db6f192 100644
--- a/src/main/java/net/dv8tion/jda/api/events/DisconnectEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/session/SessionDisconnectEvent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.dv8tion.jda.api.events;
+package net.dv8tion.jda.api.events.session;
import com.neovisionaries.ws.client.WebSocketFrame;
import net.dv8tion.jda.api.JDA;
@@ -29,22 +29,21 @@
* unless {@link net.dv8tion.jda.api.JDABuilder#setAutoReconnect(boolean) JDABuilder.setAutoReconnect(Boolean)}
* has been provided {@code false} or the disconnect was too fatal in which case a {@link ShutdownEvent} is fired.
*
- * When reconnecting was successful either a {@link net.dv8tion.jda.api.events.ReconnectedEvent ReconnectEvent}
- * or {@link net.dv8tion.jda.api.events.ResumedEvent ResumedEvent} is fired.
+ * When reconnecting was successful either a {@link SessionRecreateEvent} or {@link SessionResumeEvent} is fired.
*/
-public class DisconnectEvent extends Event
+public class SessionDisconnectEvent extends GenericSessionEvent
{
protected final WebSocketFrame serverCloseFrame;
protected final WebSocketFrame clientCloseFrame;
protected final boolean closedByServer;
protected final OffsetDateTime disconnectTime;
- public DisconnectEvent(
+ public SessionDisconnectEvent(
@Nonnull JDA api,
@Nullable WebSocketFrame serverCloseFrame, @Nullable WebSocketFrame clientCloseFrame,
boolean closedByServer, @Nonnull OffsetDateTime disconnectTime)
{
- super(api);
+ super(api, SessionState.DISCONNECTED);
this.serverCloseFrame = serverCloseFrame;
this.clientCloseFrame = clientCloseFrame;
this.closedByServer = closedByServer;
diff --git a/src/main/java/net/dv8tion/jda/api/events/session/SessionInvalidateEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/SessionInvalidateEvent.java
new file mode 100644
index 0000000000..e844d86ea6
--- /dev/null
+++ b/src/main/java/net/dv8tion/jda/api/events/session/SessionInvalidateEvent.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dv8tion.jda.api.events.session;
+
+import net.dv8tion.jda.api.JDA;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Indicates that the JDA cache has been invalidated.
+ * Can be used to mark the continuation of event flow which was stopped by the {@link net.dv8tion.jda.api.events.DisconnectEvent DisconnectEvent}.
+ * Can be used to mark the continuation of event flow which was stopped by the {@link SessionDisconnectEvent}.
* User should replace any cached Objects (like User/Guild objects).
*/
-public class ReconnectedEvent extends Event
+public class SessionRecreateEvent extends GenericSessionEvent
{
- public ReconnectedEvent(@Nonnull JDA api, long responseNumber)
+ public SessionRecreateEvent(@Nonnull JDA api)
{
- super(api, responseNumber);
+ super(api, SessionState.RECREATED);
}
}
diff --git a/src/main/java/net/dv8tion/jda/api/events/ResumedEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/SessionResumeEvent.java
similarity index 73%
rename from src/main/java/net/dv8tion/jda/api/events/ResumedEvent.java
rename to src/main/java/net/dv8tion/jda/api/events/session/SessionResumeEvent.java
index 151be2fd5c..09e0caf9dd 100644
--- a/src/main/java/net/dv8tion/jda/api/events/ResumedEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/session/SessionResumeEvent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.dv8tion.jda.api.events;
+package net.dv8tion.jda.api.events.session;
import net.dv8tion.jda.api.JDA;
@@ -23,12 +23,12 @@
* Indicates that JDA successfully resumed its connection to the gateway.
* Can be used to marks the continuation of event flow stopped by the {@link net.dv8tion.jda.api.events.DisconnectEvent DisconnectEvent}.
+ * Can be used to detect the continuation of event flow stopped by the {@link SessionDisconnectEvent}.
*/
-public class ResumedEvent extends Event
+public class SessionResumeEvent extends GenericSessionEvent
{
- public ResumedEvent(@Nonnull JDA api, long responseNumber)
+ public SessionResumeEvent(@Nonnull JDA api)
{
- super(api, responseNumber);
+ super(api, SessionState.RESUMED);
}
}
diff --git a/src/main/java/net/dv8tion/jda/api/events/session/SessionState.java b/src/main/java/net/dv8tion/jda/api/events/session/SessionState.java
new file mode 100644
index 0000000000..4c326f43b9
--- /dev/null
+++ b/src/main/java/net/dv8tion/jda/api/events/session/SessionState.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dv8tion.jda.api.events.session;
+
+/**
+ * State of a gateway session.
+ *
+ * @see GenericSessionEvent
+ */
+public enum SessionState
+{
+ /**
+ * The session is fully loaded, including all guilds.
+ *
+ * @see ReadyEvent
+ */
+ READY,
+
+ /**
+ * The session cache has been invalidated.
+ *
+ * @see SessionInvalidateEvent
+ */
+ INVALIDATED,
+
+ /**
+ * The session has disconnected, possibly to resume.
+ *
+ * @see SessionDisconnectEvent
+ */
+ DISCONNECTED,
+
+ /**
+ * The session has resumed successfully after disconnecting.
+ *
+ * @see SessionResumeEvent
+ */
+ RESUMED,
+
+ /**
+ * The session has been recreated after being {@link #INVALIDATED invalidated}.
+ *
+ * @see SessionRecreateEvent
+ */
+ RECREATED,
+
+ /**
+ * The session has been closed and will not be reconnected.
+ *
+ * @see ShutdownEvent
+ */
+ SHUTDOWN,
+}
diff --git a/src/main/java/net/dv8tion/jda/api/events/ShutdownEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/ShutdownEvent.java
similarity index 94%
rename from src/main/java/net/dv8tion/jda/api/events/ShutdownEvent.java
rename to src/main/java/net/dv8tion/jda/api/events/session/ShutdownEvent.java
index 01b4f4cdd0..184d962142 100644
--- a/src/main/java/net/dv8tion/jda/api/events/ShutdownEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/session/ShutdownEvent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.dv8tion.jda.api.events;
+package net.dv8tion.jda.api.events.session;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.requests.CloseCode;
@@ -26,14 +26,14 @@
* Indicates that JDA has fully disconnected from Discord and will not attempt to reconnect again.
* This can be useful to track connection issues.
+ *
+ * @see net.dv8tion.jda.api.events.session.GenericSessionEvent
+ * @see net.dv8tion.jda.api.events.session.SessionState
+ */
+package net.dv8tion.jda.api.events.session;
diff --git a/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java b/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java
index 6d8c362982..b5628a1ba1 100644
--- a/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java
+++ b/src/main/java/net/dv8tion/jda/api/hooks/ListenerAdapter.java
@@ -60,6 +60,7 @@
import net.dv8tion.jda.api.events.role.RoleDeleteEvent;
import net.dv8tion.jda.api.events.role.update.*;
import net.dv8tion.jda.api.events.self.*;
+import net.dv8tion.jda.api.events.session.*;
import net.dv8tion.jda.api.events.stage.GenericStageInstanceEvent;
import net.dv8tion.jda.api.events.stage.StageInstanceCreateEvent;
import net.dv8tion.jda.api.events.stage.StageInstanceDeleteEvent;
@@ -124,12 +125,15 @@ public void onGenericUpdate(@Nonnull UpdateEvent, ?> event) {}
public void onRawGateway(@Nonnull RawGatewayEvent event) {}
public void onGatewayPing(@Nonnull GatewayPingEvent event) {}
- //JDA Events
+ //Session Events
public void onReady(@Nonnull ReadyEvent event) {}
- public void onResumed(@Nonnull ResumedEvent event) {}
- public void onReconnected(@Nonnull ReconnectedEvent event) {}
- public void onDisconnect(@Nonnull DisconnectEvent event) {}
+ public void onSessionInvalidate(@Nonnull SessionInvalidateEvent event) {}
+ public void onSessionDisconnect(@Nonnull SessionDisconnectEvent event) {}
+ public void onSessionResume(@Nonnull SessionResumeEvent event) {}
+ public void onSessionRecreate(@Nonnull SessionRecreateEvent event) {}
public void onShutdown(@Nonnull ShutdownEvent event) {}
+
+ //Status Events
public void onStatusChange(@Nonnull StatusChangeEvent event) {}
public void onException(@Nonnull ExceptionEvent event) {}
@@ -280,9 +284,6 @@ public void onGuildMemberUpdateTimeOut(@Nonnull GuildMemberUpdateTimeOutEvent ev
//Guild Voice Events
public void onGuildVoiceUpdate(@Nonnull GuildVoiceUpdateEvent event) {}
- public void onGuildVoiceJoin(@Nonnull GuildVoiceJoinEvent event) {}
- public void onGuildVoiceMove(@Nonnull GuildVoiceMoveEvent event) {}
- public void onGuildVoiceLeave(@Nonnull GuildVoiceLeaveEvent event) {}
public void onGuildVoiceMute(@Nonnull GuildVoiceMuteEvent event) {}
public void onGuildVoiceDeafen(@Nonnull GuildVoiceDeafenEvent event) {}
public void onGuildVoiceGuildMute(@Nonnull GuildVoiceGuildMuteEvent event) {}
@@ -319,7 +320,7 @@ public void onEmojiUpdateRoles(@Nonnull EmojiUpdateRolesEvent event) {}
public void onGenericPrivilegeUpdate(@Nonnull GenericPrivilegeUpdateEvent event) {}
public void onApplicationCommandUpdatePrivileges(@Nonnull ApplicationCommandUpdatePrivilegesEvent event) {}
public void onApplicationUpdatePrivileges(@Nonnull ApplicationUpdatePrivilegesEvent event) {}
-
+
//Sticker Events
public void onGuildStickerAdded(@Nonnull GuildStickerAddedEvent event) {}
public void onGuildStickerRemoved(@Nonnull GuildStickerRemovedEvent event) {}
@@ -334,6 +335,7 @@ public void onGuildStickerUpdateAvailable(@Nonnull GuildStickerUpdateAvailableEv
public void onHttpRequest(@Nonnull HttpRequestEvent event) {}
//Generic Events
+ public void onGenericSessionEvent(@Nonnull GenericSessionEvent event) {}
public void onGenericInteractionCreate(@Nonnull GenericInteractionCreateEvent event) {}
public void onGenericAutoCompleteInteraction(@Nonnull GenericAutoCompleteInteractionEvent event) {}
public void onGenericComponentInteractionCreate(@Nonnull GenericComponentInteractionCreateEvent event) {}
diff --git a/src/main/java/net/dv8tion/jda/internal/handle/GuildMemberRemoveHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/GuildMemberRemoveHandler.java
index 5d3a569f80..2c09c8a181 100644
--- a/src/main/java/net/dv8tion/jda/internal/handle/GuildMemberRemoveHandler.java
+++ b/src/main/java/net/dv8tion/jda/internal/handle/GuildMemberRemoveHandler.java
@@ -19,7 +19,7 @@
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
-import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
+import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
import net.dv8tion.jda.api.utils.cache.CacheView;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
@@ -81,7 +81,7 @@ protected Long handleInternally(DataObject content)
if (connected != null) // user left channel!
{
getJDA().handleEvent(
- new GuildVoiceLeaveEvent(
+ new GuildVoiceUpdateEvent(
getJDA(), responseNumber,
connected, channel));
}
@@ -96,14 +96,14 @@ protected Long handleInternally(DataObject content)
}
GuildVoiceStateImpl voiceState = (GuildVoiceStateImpl) member.getVoiceState();
- if (voiceState != null && voiceState.inAudioChannel())//If this user was in an AudioChannel, fire VoiceLeaveEvent.
+ if (voiceState != null && voiceState.inAudioChannel()) //If this user was in an AudioChannel, fire VoiceLeaveEvent.
{
AudioChannel channel = voiceState.getChannel();
voiceState.setConnectedChannel(null);
((AudioChannelMixin>) channel).getConnectedMembersMap().remove(userId);
getJDA().handleEvent(
- new GuildVoiceLeaveEvent(
+ new GuildVoiceUpdateEvent(
getJDA(), responseNumber,
member, channel));
}
diff --git a/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java
index 4bb569b5b7..635a7295f9 100644
--- a/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java
+++ b/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java
@@ -178,11 +178,6 @@ private void handleGuildVoiceState(DataObject content)
{
((AudioChannelMixin>) channel).getConnectedMembersMap().put(userId, member);
getJDA().getEntityBuilder().updateMemberCache(member);
-
- getJDA().handleEvent(
- new GuildVoiceJoinEvent(
- getJDA(), responseNumber,
- member));
}
else if (channel == null)
{
@@ -190,11 +185,6 @@ else if (channel == null)
if (isSelf)
getJDA().getDirectAudioController().update(guild, null);
getJDA().getEntityBuilder().updateMemberCache(member, memberJson.isNull("joined_at"));
-
- getJDA().handleEvent(
- new GuildVoiceLeaveEvent(
- getJDA(), responseNumber,
- member, oldChannel));
}
else
{
@@ -220,11 +210,12 @@ else if (channel == null)
((AudioChannelMixin>) oldChannel).getConnectedMembersMap().remove(userId);
getJDA().getEntityBuilder().updateMemberCache(member);
- getJDA().handleEvent(
- new GuildVoiceMoveEvent(
- getJDA(), responseNumber,
- member, oldChannel));
}
+
+ getJDA().handleEvent(
+ new GuildVoiceUpdateEvent(
+ getJDA(), responseNumber,
+ member, oldChannel));
}
if (isSelf && voiceInterceptor != null)
diff --git a/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java b/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java
index e59fac7c00..74bbc293c2 100644
--- a/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java
+++ b/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java
@@ -24,7 +24,9 @@
import net.dv8tion.jda.api.audio.hooks.ConnectionStatus;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
-import net.dv8tion.jda.api.events.*;
+import net.dv8tion.jda.api.events.ExceptionEvent;
+import net.dv8tion.jda.api.events.RawGatewayEvent;
+import net.dv8tion.jda.api.events.session.*;
import net.dv8tion.jda.api.exceptions.ParsingException;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.requests.CloseCode;
@@ -199,19 +201,19 @@ public void ready()
JDAImpl.LOG.warn("For more info see https://git.io/vrFWP");
}
JDAImpl.LOG.info("Finished Loading!");
- api.handleEvent(new ReadyEvent(api, api.getResponseTotal()));
+ api.handleEvent(new ReadyEvent(api));
}
else
{
updateAudioManagerReferences();
JDAImpl.LOG.info("Finished (Re)Loading!");
- api.handleEvent(new ReconnectedEvent(api, api.getResponseTotal()));
+ api.handleEvent(new SessionRecreateEvent(api));
}
}
else
{
JDAImpl.LOG.debug("Successfully resumed Session!");
- api.handleEvent(new ResumedEvent(api, api.getResponseTotal()));
+ api.handleEvent(new SessionResumeEvent(api));
}
api.setStatus(JDA.Status.CONNECTED);
}
@@ -514,7 +516,7 @@ else if (clientCloseFrame != null)
}
if (isInvalidate)
invalidate(); // 1000 means our session is dropped so we cannot resume
- api.handleEvent(new DisconnectEvent(api, serverCloseFrame, clientCloseFrame, closedByServer, OffsetDateTime.now()));
+ api.handleEvent(new SessionDisconnectEvent(api, serverCloseFrame, clientCloseFrame, closedByServer, OffsetDateTime.now()));
try
{
handleReconnect(rawCloseCode);
@@ -764,6 +766,8 @@ protected void invalidate()
api.getEventCache().clear();
api.getGuildSetupController().clearCache();
chunkManager.clear();
+
+ api.handleEvent(new SessionInvalidateEvent(api));
}
protected void updateAudioManagerReferences()
These are specific depending on the event that has been received by the gateway connection.
*
*
Some events are specific for JDA internal events such as the {@link net.dv8tion.jda.api.events.ReadyEvent ReadyEvent}
+ *
Some events are specific for JDA internal events such as the {@link net.dv8tion.jda.api.events.session.ReadyEvent ReadyEvent}
* which is only fired when JDA finishes to setup its internal cache.
*/
package net.dv8tion.jda.api.events;
diff --git a/src/main/java/net/dv8tion/jda/api/events/session/GenericSessionEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/GenericSessionEvent.java
new file mode 100644
index 0000000000..ac777479f6
--- /dev/null
+++ b/src/main/java/net/dv8tion/jda/api/events/session/GenericSessionEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dv8tion.jda.api.events.session;
+
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.events.Event;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Events which update the gateway session status.
+ *
Any previously acquired entities will no longer be updated and instead new entities will be allocated.
+ */
+public class SessionInvalidateEvent extends GenericSessionEvent
+{
+ public SessionInvalidateEvent(@Nonnull JDA api)
+ {
+ super(api, SessionState.INVALIDATED);
+ }
+}
diff --git a/src/main/java/net/dv8tion/jda/api/events/ReconnectedEvent.java b/src/main/java/net/dv8tion/jda/api/events/session/SessionRecreateEvent.java
similarity index 79%
rename from src/main/java/net/dv8tion/jda/api/events/ReconnectedEvent.java
rename to src/main/java/net/dv8tion/jda/api/events/session/SessionRecreateEvent.java
index 8df1e5130d..3a8567d448 100644
--- a/src/main/java/net/dv8tion/jda/api/events/ReconnectedEvent.java
+++ b/src/main/java/net/dv8tion/jda/api/events/session/SessionRecreateEvent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.dv8tion.jda.api.events;
+package net.dv8tion.jda.api.events.session;
import net.dv8tion.jda.api.JDA;
@@ -23,13 +23,13 @@
* Indicates if JDA successfully re-established its connection to the gateway.
*
All Objects have been replaced when this is fired and events were likely missed in the downtime.
*
- *
All Objects are still in place and events are replayed.
*
- *
At this stage all internal cache is invalid!
*/
-public class ShutdownEvent extends Event
+public class ShutdownEvent extends GenericSessionEvent
{
protected final OffsetDateTime shutdownTime;
protected final int code;
public ShutdownEvent(@Nonnull JDA api, @Nonnull OffsetDateTime shutdownTime, int code)
{
- super(api);
+ super(api, SessionState.SHUTDOWN);
this.shutdownTime = shutdownTime;
this.code = code;
}
diff --git a/src/main/java/net/dv8tion/jda/api/events/session/package-info.java b/src/main/java/net/dv8tion/jda/api/events/session/package-info.java
new file mode 100644
index 0000000000..249ba7a572
--- /dev/null
+++ b/src/main/java/net/dv8tion/jda/api/events/session/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Events about the current gateway connection state.
+ *
+ *