Skip to content

Commit 63329c9

Browse files
First pass on new event docs (discord-jda#636)
* Restructure GenericMessageEvent (discord-jda#637) * Added UpdateEvent abstraction * Added note for TextChannel.deleteMessages in Message.delete documentation * Fixed > tag in StatsUpdateEvent docs
1 parent 6562437 commit 63329c9

File tree

155 files changed

+3308
-900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3308
-900
lines changed

src/main/java/net/dv8tion/jda/core/entities/Message.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ public interface Message extends ISnowflake, Formattable
709709
* a {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} and the current account has
710710
* {@link net.dv8tion.jda.core.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE} in the channel.
711711
*
712+
* <p><u>To delete up 100 messages at once in a {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}
713+
* you should use {@link net.dv8tion.jda.core.entities.TextChannel#deleteMessages(java.util.Collection) TextChannel.deleteMessages(Collection)}</u>
714+
*
712715
* <p>The following {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} are possible:
713716
* <ul>
714717
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
@@ -738,6 +741,8 @@ public interface Message extends ISnowflake, Formattable
738741
* {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}.
739742
*
740743
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
744+
*
745+
* @see net.dv8tion.jda.core.entities.TextChannel#deleteMessages(java.util.Collection) TextChannel.deleteMessages(Collection)
741746
*/
742747
@CheckReturnValue
743748
AuditableRestAction<Void> delete();
@@ -1217,7 +1222,7 @@ protected Response openConnection() throws IOException
12171222

12181223
/**
12191224
* The size of the attachment in bytes.
1220-
* <br>Example: if {@link #getSize() getSize()} returns 1024, then the attachment is 1024 bytes, or 1KB, in size.
1225+
* <br>Example: if {@code getSize()} returns 1024, then the attachment is 1024 bytes, or 1KiB, in size.
12211226
*
12221227
* @return Positive int containing the size of the Attachment.
12231228
*/

src/main/java/net/dv8tion/jda/core/events/DisconnectEvent.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
* Indicates that JDA has been disconnected from the remote server.
2727
* <br>When this event is fired JDA will try to reconnect if possible
2828
* unless {@link net.dv8tion.jda.core.JDABuilder#setAutoReconnect(boolean) JDABuilder.setAutoReconnect(Boolean)}
29-
* has been provided {@code false}!
29+
* has been provided {@code false} or the disconnect was too fatal.
3030
*
3131
* <p>When reconnecting was successful either a {@link net.dv8tion.jda.core.events.ReconnectedEvent ReconnectEvent}
32-
* or a {@link net.dv8tion.jda.core.events.ResumedEvent ResumedEvent} is fired
32+
* or a {@link net.dv8tion.jda.core.events.ResumedEvent ResumedEvent} is fired.
3333
*/
3434
public class DisconnectEvent extends Event
3535
{
@@ -38,10 +38,12 @@ public class DisconnectEvent extends Event
3838
protected final boolean closedByServer;
3939
protected final OffsetDateTime disconnectTime;
4040

41-
public DisconnectEvent(JDA api, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer,
42-
OffsetDateTime disconnectTime)
41+
public DisconnectEvent(
42+
JDA api,
43+
WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame,
44+
boolean closedByServer, OffsetDateTime disconnectTime)
4345
{
44-
super(api, -1);
46+
super(api);
4547
this.serverCloseFrame = serverCloseFrame;
4648
this.clientCloseFrame = clientCloseFrame;
4749
this.closedByServer = closedByServer;
@@ -76,21 +78,41 @@ public List<String> getCloudflareRays()
7678
return api.getCloudflareRays();
7779
}
7880

81+
/**
82+
* The close frame discord sent to us
83+
*
84+
* @return The {@link com.neovisionaries.ws.client.WebSocketFrame WebSocketFrame} discord sent as closing handshake
85+
*/
7986
public WebSocketFrame getServiceCloseFrame()
8087
{
8188
return serverCloseFrame;
8289
}
8390

91+
/**
92+
* The close frame we sent to discord
93+
*
94+
* @return The {@link com.neovisionaries.ws.client.WebSocketFrame WebSocketFrame} we sent as closing handshake
95+
*/
8496
public WebSocketFrame getClientCloseFrame()
8597
{
8698
return clientCloseFrame;
8799
}
88100

101+
/**
102+
* Whether the connection was closed by discord
103+
*
104+
* @return True, if discord closed our connection
105+
*/
89106
public boolean isClosedByServer()
90107
{
91108
return closedByServer;
92109
}
93110

111+
/**
112+
* Time at which we noticed the disconnection
113+
*
114+
* @return Time of closure
115+
*/
94116
public OffsetDateTime getDisconnectTime()
95117
{
96118
return disconnectTime;

src/main/java/net/dv8tion/jda/core/events/Event.java

+30-9
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,47 @@
1818
import net.dv8tion.jda.core.JDA;
1919

2020
/**
21-
* <b><u>Event</u></b><br>
22-
* Fired for every event.<br>
23-
* All events JDA fires are based on an instance of this class.<br>
24-
* <br>
25-
* Use: Used in {@link net.dv8tion.jda.core.hooks.EventListener EventListener} implementations to distinguish what event is being fired.<br><br>
26-
* Example implementation: {@link net.dv8tion.jda.core.hooks.ListenerAdapter ListenerAdapter}
21+
* Top-level event type
22+
* <br>All events JDA fires are derived from this class.
23+
*
24+
* <p>Can be used to check if an Object is a JDA event in {@link net.dv8tion.jda.core.hooks.EventListener EventListener} implementations to distinguish what event is being fired.
25+
* <br>Adapter implementation: {@link net.dv8tion.jda.core.hooks.ListenerAdapter ListenerAdapter}
2726
*/
2827
public abstract class Event
2928
{
3029
protected final JDA api;
3130
protected final long responseNumber;
3231

32+
/**
33+
* Creates a new Event from the given JDA instance
34+
*
35+
* @param api
36+
* Current JDA instance
37+
* @param responseNumber
38+
* The sequence number for this event
39+
*
40+
* @see #Event(net.dv8tion.jda.core.JDA)
41+
*/
3342
public Event(JDA api, long responseNumber)
3443
{
3544
this.api = api;
3645
this.responseNumber = responseNumber;
3746
}
3847

48+
/**
49+
* Creates a new Event from the given JDA instance
50+
* <br>Uses the current {@link net.dv8tion.jda.core.JDA#getResponseTotal()} as sequence
51+
*
52+
* @param api
53+
* Current JDA instance
54+
*/
3955
public Event(JDA api)
4056
{
41-
this.api = api;
42-
this.responseNumber = api.getResponseTotal();
57+
this(api, api.getResponseTotal());
4358
}
4459

4560
/**
46-
* Returns the JDA instance corresponding to this Event
61+
* The current JDA instance corresponding to this Event
4762
*
4863
* @return The corresponding JDA instance
4964
*/
@@ -52,6 +67,12 @@ public JDA getJDA()
5267
return api;
5368
}
5469

70+
/**
71+
* The current sequence for this event.
72+
* <br>This can be used to keep events in order when making sequencing system.
73+
*
74+
* @return The current sequence number for this event
75+
*/
5576
public long getResponseNumber()
5677
{
5778
return responseNumber;

src/main/java/net/dv8tion/jda/core/events/ExceptionEvent.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import net.dv8tion.jda.core.JDA;
2020

2121
/**
22-
* Fired when JDA does not have a specific handling for a Throwable.
23-
* <br>This includes {@link java.lang.Error Errors} and {@link com.neovisionaries.ws.client.WebSocketException WebSocketExceptions}
22+
* Indicates that JDA encountered a Throwable that could not be forwarded to another end-user frontend.
23+
* <br>For instance this is fired for events in internal WebSocket handling or audio threads.
24+
* This includes {@link java.lang.Error Errors} and {@link com.neovisionaries.ws.client.WebSocketException WebSocketExceptions}
2425
*
2526
* <p>It is not recommended to simply use this and print each event as some throwables where already logged
2627
* by JDA. See {@link #isLogged()}.
@@ -32,7 +33,7 @@ public class ExceptionEvent extends Event
3233

3334
public ExceptionEvent(JDA api, Throwable throwable, boolean logged)
3435
{
35-
super(api, -1);
36+
super(api);
3637
this.throwable = throwable;
3738
this.logged = logged;
3839
}

src/main/java/net/dv8tion/jda/core/events/ReadyEvent.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import net.dv8tion.jda.core.JDA;
1919

2020
/**
21-
* <b><u>ReadyEvent</u></b><br>
22-
* Fired if our connection finished loading the ready event.<br>
23-
* Before this event was fired all entity related functions (like JDA#getUserById(String)) were not guaranteed to work as expected.<br>
24-
* <br>
25-
* Use: JDA finished populating internal objects and is now ready to be used. When this is fired all entities are cached and accessible.
21+
* Indicates that JDA finished loading all entities.
22+
* <br>Before this event was fired all entity related functions were not guaranteed to work as expected.
23+
*
24+
* <p>Can be used to indicate when JDA finished populating internal objects and is ready to be used.
25+
* When this is fired all entities are cached and accessible.
2626
*/
2727
public class ReadyEvent extends Event
2828
{

src/main/java/net/dv8tion/jda/core/events/ReconnectedEvent.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import net.dv8tion.jda.core.JDA;
1919

2020
/**
21-
* <b><u>ReconnectedEvent</u></b><br>
22-
* Fired if JDA successfully re-established it's connection to the WebSocket.<br>
23-
* All Objects have been replaced when this is fired and events were likely missed in the downtime.<br>
24-
* <br>
25-
* Use: This marks the continuation of event flow stopped by the {@link net.dv8tion.jda.core.events.DisconnectEvent DisconnectEvent}. User should replace any cached Objects (like User/Guild objects).
21+
* Indicates if JDA successfully re-established its connection to the gateway.
22+
* <br>All Objects have been replaced when this is fired and events were likely missed in the downtime.
23+
*
24+
* <p>Can be used to mark the continuation of event flow which was stopped by the {@link net.dv8tion.jda.core.events.DisconnectEvent DisconnectEvent}.
25+
* User should replace any cached Objects (like User/Guild objects).
2626
*/
2727
public class ReconnectedEvent extends Event
2828
{

src/main/java/net/dv8tion/jda/core/events/ResumedEvent.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
import net.dv8tion.jda.core.JDA;
1919

2020
/**
21-
* <b><u>ResumedEvent</u></b><br>
22-
* Fired if JDA successfully re-established it's connection to the WebSocket.<br>
23-
* All Objects are still in place and events are replayed.<br>
24-
* <br>
25-
* Use: This marks the continuation of event flow stopped by the {@link net.dv8tion.jda.core.events.DisconnectEvent DisconnectEvent}.
21+
* Indicates that JDA successfully resumed its connection to the gateway.
22+
* <br>All Objects are still in place and events are replayed.
23+
*
24+
* <p>Can be used to marks the continuation of event flow stopped by the {@link net.dv8tion.jda.core.events.DisconnectEvent DisconnectEvent}.
2625
*/
2726
public class ResumedEvent extends Event
2827
{

src/main/java/net/dv8tion/jda/core/events/ShutdownEvent.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import java.time.OffsetDateTime;
2222

2323
/**
24-
* Indicates that JDA has fully disconnected from Discord
25-
* and will not attempt to reconnect again.
24+
* Indicates that JDA has fully disconnected from Discord and will not attempt to reconnect again.
2625
* <br>At this stage all internal cache is invalid!
2726
*/
2827
public class ShutdownEvent extends Event
@@ -32,7 +31,7 @@ public class ShutdownEvent extends Event
3231

3332
public ShutdownEvent(JDA api, OffsetDateTime shutdownTime, int code)
3433
{
35-
super(api, -1);
34+
super(api);
3635
this.shutdownTime = shutdownTime;
3736
this.code = code;
3837
}

src/main/java/net/dv8tion/jda/core/events/StatusChangeEvent.java

+63-6
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,87 @@
1818
import net.dv8tion.jda.core.JDA;
1919

2020
/**
21-
* <b><u>StatusChangedEvent</u></b><br>
22-
* Fired if our {@link net.dv8tion.jda.core.JDA.Status Status} changed. (Example: SHUTTING_DOWN -&gt; SHUTDOWN)<br>
23-
* <br>
24-
* Use: Detect internal status changes. Possibly to log or forward on user's end.
21+
* Indicates that our {@link net.dv8tion.jda.core.JDA.Status Status} changed. (Example: SHUTTING_DOWN {@literal ->} SHUTDOWN)
22+
*
23+
* <br>Can be used to detect internal status changes. Possibly to log or forward on user's end.
24+
*
25+
* <p>Identifier: {@code status}
2526
*/
26-
public class StatusChangeEvent extends Event
27+
public class StatusChangeEvent extends Event implements UpdateEvent<JDA, JDA.Status>
2728
{
29+
public static final String IDENTIFIER = "status";
30+
2831
protected final JDA.Status newStatus;
2932
protected final JDA.Status oldStatus;
3033

3134
public StatusChangeEvent(JDA api, JDA.Status newStatus, JDA.Status oldStatus)
3235
{
33-
super(api, -1);
36+
super(api);
3437
this.newStatus = newStatus;
3538
this.oldStatus = oldStatus;
3639
}
3740

41+
/**
42+
* The status that we changed to
43+
*
44+
* @return The new status
45+
*
46+
* @deprecated
47+
* Use {@link #getNewStatus()} instead
48+
*/
49+
@Deprecated
3850
public JDA.Status getStatus()
3951
{
4052
return newStatus;
4153
}
4254

55+
/**
56+
* The status that we changed to
57+
*
58+
* @return The new status
59+
*/
60+
public JDA.Status getNewStatus()
61+
{
62+
return newStatus;
63+
}
64+
65+
/**
66+
* The previous status
67+
*
68+
* @return The previous status
69+
*/
4370
public JDA.Status getOldStatus()
4471
{
4572
return oldStatus;
4673
}
74+
75+
@Override
76+
public String getPropertyIdentifier()
77+
{
78+
return IDENTIFIER;
79+
}
80+
81+
@Override
82+
public JDA getEntity()
83+
{
84+
return getJDA();
85+
}
86+
87+
@Override
88+
public JDA.Status getOldValue()
89+
{
90+
return oldStatus;
91+
}
92+
93+
@Override
94+
public JDA.Status getNewValue()
95+
{
96+
return newStatus;
97+
}
98+
99+
@Override
100+
public String toString()
101+
{
102+
return "StatusUpdate(" + getOldStatus() + "->" + getNewStatus() + ')';
103+
}
47104
}

0 commit comments

Comments
 (0)