papermc/Spigot-API-Patches/0235-Add-API-for-quit-reason.patch
Mariell Hoversholm b6d9d63436 Add API for quit reason
The following has been tested:
- Disconnect from menu -> DISCONNECTED
- EssentialsX kick -> KICKED
- Suspend server JVM -> DISCONNECTED
- Suspend client JVM -> TIMED_OUT
- Call #exceptionCaught -> ERRONEOUS_STATE

Suspension was done through `kill -STOP` and subsequently `kill -CONT`
after the player has (been) disconnected.

Closes #254.
2020-11-14 21:22:41 +01:00

68 lines
2.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sat, 14 Nov 2020 16:19:58 +0100
Subject: [PATCH] Add API for quit reason
diff --git a/src/main/java/org/bukkit/event/player/PlayerQuitEvent.java b/src/main/java/org/bukkit/event/player/PlayerQuitEvent.java
index d70c25f404e994766a9ebce89a917c8d0719777c..af52a5dfb452da11e51cad9c882cae1533cba520 100644
--- a/src/main/java/org/bukkit/event/player/PlayerQuitEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerQuitEvent.java
@@ -10,10 +10,17 @@ import org.jetbrains.annotations.Nullable;
*/
public class PlayerQuitEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
+ private final QuitReason reason; // Paper
private String quitMessage;
public PlayerQuitEvent(@NotNull final Player who, @Nullable final String quitMessage) {
+ // Paper start
+ this(who, quitMessage, null);
+ }
+ public PlayerQuitEvent(@NotNull final Player who, @Nullable final String quitMessage, @Nullable QuitReason quitReason) {
super(who);
+ this.reason = quitReason == null ? QuitReason.DISCONNECTED : quitReason;
+ // Paper end
this.quitMessage = quitMessage;
}
@@ -46,4 +53,39 @@ public class PlayerQuitEvent extends PlayerEvent {
public static HandlerList getHandlerList() {
return handlers;
}
+
+ // Paper start
+ @NotNull
+ public QuitReason getReason() {
+ return this.reason;
+ }
+
+ public enum QuitReason {
+ /**
+ * The player left on their own behalf.
+ * <p>
+ * This does not mean they pressed the disconnect button in their client, but rather that the client severed the
+ * connection themselves. This may occur if no keep-alive packet is received on their side, among other things.
+ */
+ DISCONNECTED,
+
+ /**
+ * The player was kicked from the server.
+ */
+ KICKED,
+
+ /**
+ * The player has timed out.
+ */
+ TIMED_OUT,
+
+ /**
+ * The player's connection has entered an erroneous state.
+ * <p>
+ * Reasons for this may include invalid packets, invalid data, and uncaught exceptions in the packet handler,
+ * among others.
+ */
+ ERRONEOUS_STATE,
+ }
+ // Paper end
}