mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
Add API for quit reason
This commit is contained in:
parent
40ac3e15db
commit
7ee931eaf2
1 changed files with 47 additions and 0 deletions
|
@ -11,16 +11,28 @@ import org.jetbrains.annotations.Nullable;
|
||||||
public class PlayerQuitEvent extends PlayerEvent {
|
public class PlayerQuitEvent extends PlayerEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private net.kyori.adventure.text.Component quitMessage; // Paper
|
private net.kyori.adventure.text.Component quitMessage; // Paper
|
||||||
|
private final QuitReason reason; // Paper
|
||||||
|
|
||||||
@Deprecated // Paper
|
@Deprecated // Paper
|
||||||
public PlayerQuitEvent(@NotNull final Player who, @Nullable final String quitMessage) {
|
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);
|
super(who);
|
||||||
this.quitMessage = quitMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(quitMessage) : null; // Paper
|
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
|
// Paper start
|
||||||
|
@Deprecated
|
||||||
public PlayerQuitEvent(@NotNull final Player who, @Nullable final net.kyori.adventure.text.Component quitMessage) {
|
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);
|
super(who);
|
||||||
this.quitMessage = quitMessage;
|
this.quitMessage = quitMessage;
|
||||||
|
this.reason = quitReason == null ? QuitReason.DISCONNECTED : quitReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,4 +87,39 @@ public class PlayerQuitEvent extends PlayerEvent {
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue