2020-11-14 15:23:10 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sat, 14 Nov 2020 16:19:52 +0100
Subject: [PATCH] Add API for quit reason
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
2021-02-21 19:45:33 +00:00
index 7e5e4acb3c892a5d366e0fbfb76b97884345ec24..d58abb47c1a543eaf238569f27bf189322c22a93 100644
2020-11-14 15:23:10 +00:00
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
2021-02-21 19:45:33 +00:00
@@ -130,6 +130,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2020-11-14 15:23:10 +00:00
double lastEntitySpawnRadiusSquared; // Paper - optimise isOutsideRange, this field is in blocks
boolean needsChunkCenterUpdate; // Paper - no-tick view distance
+ public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - there are a lot of changes to do if we change all methods leading to the event
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(worldserver, worldserver.getSpawn(), worldserver.v(), gameprofile);
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
2021-01-29 00:32:08 +00:00
index fc4ad72ffaed5e747cfecc71e9ac8ee2b556ce31..fb1e3c705b8abee13695762cdfd0e9f1bfdb5ad8 100644
2020-11-14 15:23:10 +00:00
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
@@ -119,12 +119,15 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
this.u = true;
if (this.channel.isOpen()) {
+ EntityPlayer player = this.getPlayer(); // Paper
if (throwable instanceof TimeoutException) {
NetworkManager.LOGGER.debug("Timeout", throwable);
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.TIMED_OUT; // Paper
this.close(new ChatMessage("disconnect.timeout"));
} else {
ChatMessage chatmessage = new ChatMessage("disconnect.genericReason", new Object[]{"Internal Exception: " + throwable});
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.ERRONEOUS_STATE; // Paper
if (flag) {
NetworkManager.LOGGER.debug("Failed to sent packet", throwable);
this.sendPacket(new PacketPlayOutKickDisconnect(chatmessage), (future) -> {
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2021-02-22 11:12:40 +00:00
index dea7787f755013fb06c1e9b999f4b6d167cb5697..9b36afad0974ad6f8a31f940bdbbf920c7859bb3 100644
2020-11-14 15:23:10 +00:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2020-12-08 07:51:55 +00:00
@@ -298,6 +298,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2021-02-21 19:45:33 +00:00
final IChatBaseComponent ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
2020-11-14 15:23:10 +00:00
// CraftBukkit end
+ this.player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.KICKED; // Paper
this.networkManager.sendPacket(new PacketPlayOutKickDisconnect(ichatbasecomponent), (future) -> {
this.networkManager.close(ichatbasecomponent);
});
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2021-02-22 11:12:40 +00:00
index b0f432ed5ed47c867947a9285567a816da306797..27f6a9b0711a0e00c8350e45e2d0618b1f735eb8 100644
2020-11-14 15:23:10 +00:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2021-02-22 08:03:03 +00:00
@@ -512,7 +512,7 @@ public abstract class PlayerList {
2020-11-14 15:23:10 +00:00
entityplayer.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper
}
2021-02-22 11:12:40 +00:00
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, entityplayer.getBukkitEntity().displayName()));
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, entityplayer.getBukkitEntity().displayName()), entityplayer.quitReason); // Paper - quit reason
2020-11-14 15:23:10 +00:00
if (entityplayer.didPlayerJoinEvent) cserver.getPluginManager().callEvent(playerQuitEvent); // Paper - if we disconnected before join ever fired, don't fire quit
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());