Paper/patches/server/0651-Fixes-kick-event-leave-message-not-being-sent.patch

86 lines
6.0 KiB
Diff
Raw Normal View History

2021-07-09 21:03:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 7 Jul 2021 16:19:41 -0700
Subject: [PATCH] Fixes kick event leave message not being sent
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index d9cacc372e1d40e6b2b5d83c88a01121b7f3f101..72f9f443fb69603d986d41f0776e6b9b30228431 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -268,7 +268,6 @@ public class ServerPlayer extends Player {
public boolean sentListPacket = false;
public boolean supressTrackerForLogin = false; // Paper
public Integer clientViewDistance;
- public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
// CraftBukkit end
2022-12-07 21:16:54 +01:00
public boolean isRealPlayer; // Paper
public double lastEntitySpawnRadiusSquared; // Paper - optimise isOutsideRange, this field is in blocks
2021-07-09 21:03: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 d11d2dc10a8add75812f24234b8bf9c97fcb635c..7d257a0461739f0a4a59f9c17b237c44fde7c44d 100644
2021-07-09 21:03:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -513,7 +513,6 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// Do not kick the player
return;
}
- this.player.kickLeaveMessage = event.getLeaveMessage(); // CraftBukkit - SPIGOT-3034: Forward leave message to PlayerQuitEvent
// Send the possibly modified leave message
final Component ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
// CraftBukkit end
@@ -522,7 +521,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-27 23:19:52 +02:00
this.connection.send(new ClientboundDisconnectPacket(ichatbasecomponent), PacketSendListener.thenRun(() -> {
2021-07-09 21:03:28 +02:00
this.connection.disconnect(ichatbasecomponent);
2022-07-27 23:19:52 +02:00
}));
2021-07-09 21:03:28 +02:00
- this.onDisconnect(ichatbasecomponent); // CraftBukkit - fire quit instantly
+ this.onDisconnect(ichatbasecomponent, event.leaveMessage()); // CraftBukkit - fire quit instantly // Paper - use kick event leave message
this.connection.setReadOnly();
MinecraftServer minecraftserver = this.server;
Connection networkmanager = this.connection;
@@ -1983,6 +1982,11 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-07-09 21:03:28 +02:00
@Override
public void onDisconnect(Component reason) {
+ // Paper start
+ this.onDisconnect(reason, null);
+ }
+ public void onDisconnect(Component reason, @Nullable net.kyori.adventure.text.Component quitMessage) {
+ // Paper end
// CraftBukkit start - Rarely it would send a disconnect line twice
if (this.processedDisconnect) {
return;
@@ -2000,7 +2004,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-07-09 21:03:28 +02:00
this.player.disconnect();
// Paper start - Adventure
2021-11-25 00:46:26 +01:00
- net.kyori.adventure.text.Component quitMessage = this.server.getPlayerList().remove(this.player);
+ quitMessage = quitMessage == null ? this.server.getPlayerList().remove(this.player) : this.server.getPlayerList().remove(this.player, quitMessage); // Paper - pass in quitMessage to fix kick message not being used
2021-07-09 21:03:28 +02:00
if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
2022-07-27 23:19:52 +02:00
this.server.getPlayerList().broadcastSystemMessage(PaperAdventure.asVanilla(quitMessage), false);
2021-07-09 21:03:28 +02:00
// Paper end
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index dae66865e84352527f5115e37586f729d32c55cd..5db5e6b59ff996012f5b2d546f54d1f3b7442ce0 100644
2021-07-09 21:03:28 +02:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -555,6 +555,11 @@ public abstract class PlayerList {
2021-07-09 21:03:28 +02:00
}
2021-11-25 00:46:26 +01:00
public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // Paper - return Component
2021-07-09 21:03:28 +02:00
+ // Paper start
+ return this.remove(entityplayer, 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())));
2021-07-09 21:03:28 +02:00
+ }
2021-11-25 00:46:26 +01:00
+ public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) {
2021-07-09 21:03:28 +02:00
+ // Paper end
ServerLevel worldserver = entityplayer.getLevel();
entityplayer.awardStat(Stats.LEAVE_GAME);
@@ -565,7 +570,7 @@ public abstract class PlayerList {
2021-07-09 21:03: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())), entityplayer.quitReason); // Paper - Adventure & quit reason
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), leaveMessage, entityplayer.quitReason); // Paper - Adventure & quit reason
this.cserver.getPluginManager().callEvent(playerQuitEvent);
2021-07-09 21:03:28 +02:00
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());