2021-06-11 14:02:28 +02: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/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
2024-04-24 15:46:45 +02:00
index 68d5be903a0d13e59c9e4bd6d85baaf0773547a0..fe89e8f509f3972ceb71c9aa6277524baa39985b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
2024-04-24 15:46:45 +02:00
@@ -167,12 +167,15 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
2021-06-11 14:02:28 +02:00
this.handlingFault = true;
if (this.channel.isOpen()) {
2024-01-20 12:50:16 +01:00
+ net.minecraft.server.level.ServerPlayer player = this.getPlayer(); // Paper - Add API for quit reason
2021-06-11 14:02:28 +02:00
if (throwable instanceof TimeoutException) {
Connection.LOGGER.debug("Timeout", throwable);
2024-01-20 12:50:16 +01:00
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.TIMED_OUT; // Paper - Add API for quit reason
2022-06-08 08:25:32 +02:00
this.disconnect(Component.translatable("disconnect.timeout"));
2021-06-11 14:02:28 +02:00
} else {
2024-04-24 15:46:45 +02:00
MutableComponent ichatmutablecomponent = Component.translatable("disconnect.genericReason", "Internal Exception: " + String.valueOf(throwable));
2021-06-11 14:02:28 +02:00
2024-01-20 12:50:16 +01:00
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.ERRONEOUS_STATE; // Paper - Add API for quit reason
2021-06-11 14:02:28 +02:00
if (flag) {
Connection.LOGGER.debug("Failed to sent packet", throwable);
2023-09-22 06:40:51 +02:00
if (this.getSending() == PacketFlow.CLIENTBOUND) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-04-28 03:00:01 +02:00
index 4b07b5f7a92a7bfe74f157fd69ecd864df38c495..c4ba4b378aee28e7479207aff46c27307bd6b105 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-04-28 03:00:01 +02:00
@@ -291,6 +291,7 @@ public class ServerPlayer extends Player {
2021-06-14 18:58:00 +02:00
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
2024-01-22 18:04:55 +01:00
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
2024-01-20 23:13:41 +01:00
public @Nullable String clientBrandName = null; // Paper - Brand support
2024-01-20 12:50:16 +01:00
+ public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
2021-06-11 14:02:28 +02:00
2024-01-24 15:57:53 +01:00
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
2023-09-22 06:40:51 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2024-04-25 23:21:18 +02:00
index d7ddfabcbacb077c337c789083a24ad82e08e82e..2872bef40440b11a206c3ec88e2c6d95cd1a72e9 100644
2023-09-22 06:40:51 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2024-04-25 23:21:18 +02:00
@@ -371,6 +371,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 06:40:51 +02:00
final Component ichatbasecomponent = io.papermc.paper.adventure.PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
2021-06-11 14:02:28 +02:00
// CraftBukkit end
2024-01-20 12:50:16 +01:00
+ this.player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.KICKED; // Paper - Add API for quit reason
2022-07-27 22:46:05 +02:00
this.connection.send(new ClientboundDisconnectPacket(ichatbasecomponent), PacketSendListener.thenRun(() -> {
2021-06-11 14:02:28 +02:00
this.connection.disconnect(ichatbasecomponent);
2022-07-27 22:46:05 +02:00
}));
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-04-25 22:34:46 +02:00
index 97a3f29414cd9f11e6a790cb30f7ef25a836b06c..8b0b9ef372c595340c43c5882ad71587833d86bc 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-04-24 15:46:45 +02:00
@@ -576,7 +576,7 @@ public abstract class PlayerList {
2024-01-21 19:37:09 +01:00
entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper - Inventory close reason
2021-06-11 14:02:28 +02:00
}
2023-09-22 06:40:51 +02:00
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName()))); // Paper - Adventure
2024-01-20 12:50:16 +01:00
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName())), entityplayer.quitReason); // Paper - Adventure & Add API for quit reason
2022-12-19 11:46:55 +01:00
this.cserver.getPluginManager().callEvent(playerQuitEvent);
2021-06-11 14:02:28 +02:00
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());