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-26 17:54:48 +00:00
index 8436b7be989bf08c8ec1f0d646b20e777a0ebd55..3728ff515feea7fd6fe8c62c0e6646e8a8662beb 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-03-02 03:07:12 +00:00
index efd66e81492ec4f976b9db66b84f1c5d728c7a13..1f1baaa464459e06ac877ea3dcd1d30604ef8d88 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
2021-02-22 18:24:44 +00:00
@@ -302,6 +302,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-26 17:54:48 +00:00
index 24b28c547555ece196befb041025ae72b6ee7c81..2837b2c3b72a22da70ca7123715c83b4d6e701be 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-26 17:54:48 +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, com.destroystokyo.paper.PaperConfig.useDisplayNameInQuit ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getName())));
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, com.destroystokyo.paper.PaperConfig.useDisplayNameInQuit ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getName())), 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());