Paper/patches/server/0502-Add-API-for-quit-reason.patch

64 lines
5.3 KiB
Diff
Raw Normal View History

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
index 501d17ba798c5928279a93c45de3eb6e8a3f99d6..5fa1b0d609ffc43b03f66d710a2702c2597786fc 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
@@ -170,12 +170,15 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
2021-06-11 14:02:28 +02:00
this.handlingFault = true;
if (this.channel.isOpen()) {
2021-06-14 18:58:00 +02:00
+ net.minecraft.server.level.ServerPlayer player = this.getPlayer(); // Paper
2021-06-11 14:02:28 +02:00
if (throwable instanceof TimeoutException) {
Connection.LOGGER.debug("Timeout", throwable);
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.TIMED_OUT; // Paper
2022-06-08 08:25:32 +02:00
this.disconnect(Component.translatable("disconnect.timeout"));
2021-06-11 14:02:28 +02:00
} else {
2022-06-08 08:25:32 +02:00
MutableComponent ichatmutablecomponent = Component.translatable("disconnect.genericReason", "Internal Exception: " + throwable);
2021-06-11 14:02:28 +02:00
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.ERRONEOUS_STATE; // Paper
if (flag) {
Connection.LOGGER.debug("Failed to sent packet", throwable);
2021-06-14 18:58:00 +02:00
ConnectionProtocol enumprotocol = this.getCurrentProtocol();
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
index e6b175a62f2b151068fc7b28685b64afea1ebbc3..a56dd127776be6de0e88a356b917488f7b20d39c 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
@@ -268,6 +268,7 @@ public class ServerPlayer extends Player {
public double lastEntitySpawnRadiusSquared; // Paper - optimise isOutsideRange, this field is in blocks
2021-06-14 18:58:00 +02:00
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
2022-12-07 21:16:54 +01:00
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
2021-06-11 14:02:28 +02:00
+ 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
2022-12-07 21:16:54 +01:00
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index aabfccdd94d5934716a706c9189391177ff07d57..51ae3c2facb7a1dbdbc47cd681aeb6a6beb4ed72 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -503,6 +503,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
final Component ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
// CraftBukkit end
+ this.player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.KICKED; // Paper
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
index fdd7f80fe912d4f75e7c42a2dd97160031f857b7..233539a8dd7d44efad748036ae93a31d2d3e7d46 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
@@ -552,7 +552,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper
}
- 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() : PaperAdventure.asAdventure(entityplayer.getDisplayName()))); // Paper - Adventure
+ 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() : PaperAdventure.asAdventure(entityplayer.getDisplayName())), entityplayer.quitReason); // Paper - Adventure & quit reason
this.cserver.getPluginManager().callEvent(playerQuitEvent);
2021-06-11 14:02:28 +02:00
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());