aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0218-Add-API-for-quit-reason.patch
blob: 0350afaf928a827a5901fc7a18e4b6652c80e624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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 14b27eaaf744736b3e56bb1383481df98a218c43..84703b5d174625b1a4a995a244e6400d2675fbb5 100644
--- a/src/main/java/org/bukkit/event/player/PlayerQuitEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerQuitEvent.java
@@ -11,16 +11,28 @@ import org.jetbrains.annotations.Nullable;
 public class PlayerQuitEvent extends PlayerEvent {
     private static final HandlerList handlers = new HandlerList();
     private net.kyori.adventure.text.Component quitMessage; // Paper
+    private final QuitReason reason; // Paper
 
     @Deprecated // Paper
     public PlayerQuitEvent(@NotNull final Player who, @Nullable final String quitMessage) {
+        // Paper start
+        this(who, quitMessage, null);
+    }
+    @Deprecated // Paper
+    public PlayerQuitEvent(@NotNull final Player who, @Nullable final String quitMessage, @Nullable QuitReason quitReason) {
         super(who);
         this.quitMessage = quitMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(quitMessage) : null; // Paper
+        this.reason = quitReason == null ? QuitReason.DISCONNECTED : quitReason;
     }
     // Paper start
+    @Deprecated
     public PlayerQuitEvent(@NotNull final Player who, @Nullable final net.kyori.adventure.text.Component quitMessage) {
+        this(who, quitMessage, null);
+    }
+    public PlayerQuitEvent(@NotNull final Player who, @Nullable final net.kyori.adventure.text.Component quitMessage, @Nullable QuitReason quitReason) {
         super(who);
         this.quitMessage = quitMessage;
+        this.reason = quitReason == null ? QuitReason.DISCONNECTED : quitReason;
     }
 
     /**
@@ -75,4 +87,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
 }