2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 15 May 2021 20:30:45 -0700
Subject: [PATCH] Add PlayerKickEvent causes
2022-12-08 18:06:14 +01:00
diff --git a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
2023-09-22 19:59:56 +02:00
index b5f54ee82905e3e6ab5bfde35ab625f5feeb1393..c0a80824a0307ea673805015119cc834b268f0dc 100644
2022-12-08 18:06:14 +01:00
--- a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
+++ b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
@@ -39,7 +39,7 @@ public class SignedMessageChain {
} else {
PlayerChatMessage playerChatMessage = new PlayerChatMessage(signedMessageLink, signature, body, (Component)null, FilterMask.PASS_THROUGH);
if (!playerChatMessage.verify(signatureValidator)) {
- throw new SignedMessageChain.DecodeException(Component.translatable("multiplayer.disconnect.unsigned_chat"), true);
+ throw new SignedMessageChain.DecodeException(Component.translatable("multiplayer.disconnect.unsigned_chat"), true, org.bukkit.event.player.PlayerKickEvent.Cause.UNSIGNED_CHAT); // Paper - kick event causes
} else {
if (playerChatMessage.hasExpiredServer(Instant.now())) {
LOGGER.warn("Received expired chat: '{}'. Is the client/server system time unsynchronized?", (Object)body.content());
@@ -63,10 +63,17 @@ public class SignedMessageChain {
public static class DecodeException extends ThrowingComponent {
private final boolean shouldDisconnect;
+ public final org.bukkit.event.player.PlayerKickEvent.Cause kickCause; // Paper
public DecodeException(Component message, boolean shouldDisconnect) {
+ // Paper start
+ this(message, shouldDisconnect, org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN);
+ }
+ public DecodeException(Component message, boolean shouldDisconnect, org.bukkit.event.player.PlayerKickEvent.Cause kickCause) {
+ // Paper end
super(message);
this.shouldDisconnect = shouldDisconnect;
+ this.kickCause = kickCause; // Paper
}
public boolean shouldDisconnect() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2023-10-27 01:34:58 +02:00
index 1400fd3f8eb38c15e85221b5805080e1d792215f..d74313b58b660f3c03b8a6db4f80b6b073b6b795 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2023-09-22 22:13:57 +02:00
@@ -2151,7 +2151,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
2021-10-07 20:11:15 +02:00
if (!whitelist.isWhiteListed(entityplayer.getGameProfile()) && !this.getPlayerList().isOp(entityplayer.getGameProfile())) { // Paper - Fix kicking ops when whitelist is reloaded (MC-171420)
2021-06-11 14:02:28 +02:00
- entityplayer.connection.disconnect(org.spigotmc.SpigotConfig.whitelistMessage); // Paper - use configurable message
+ entityplayer.connection.disconnect(org.spigotmc.SpigotConfig.whitelistMessage, org.bukkit.event.player.PlayerKickEvent.Cause.WHITELIST); // Paper - use configurable message
}
}
diff --git a/src/main/java/net/minecraft/server/commands/BanIpCommands.java b/src/main/java/net/minecraft/server/commands/BanIpCommands.java
2023-09-22 19:59:56 +02:00
index 78345cf28be16b2e9bf2237ea60a3be424a8dabf..5397a5013bee9589b59c76ce5a2c00a7dc3ec262 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/commands/BanIpCommands.java
+++ b/src/main/java/net/minecraft/server/commands/BanIpCommands.java
2023-06-08 03:13:54 +02:00
@@ -62,7 +62,7 @@ public class BanIpCommands {
2021-06-15 05:50:26 +02:00
}
2021-06-11 14:02:28 +02:00
2021-06-15 05:50:26 +02:00
for(ServerPlayer serverPlayer : list) {
2022-06-08 11:31:06 +02:00
- serverPlayer.connection.disconnect(Component.translatable("multiplayer.disconnect.ip_banned"));
+ serverPlayer.connection.disconnect(Component.translatable("multiplayer.disconnect.ip_banned"), org.bukkit.event.player.PlayerKickEvent.Cause.IP_BANNED); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
return list.size();
diff --git a/src/main/java/net/minecraft/server/commands/BanPlayerCommands.java b/src/main/java/net/minecraft/server/commands/BanPlayerCommands.java
2023-09-22 19:59:56 +02:00
index 46f45b315011d43c081fb3f004ab62f3da67036a..42c930443505e94ca91a02e65a8df86801034280 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/commands/BanPlayerCommands.java
+++ b/src/main/java/net/minecraft/server/commands/BanPlayerCommands.java
2023-09-22 07:41:27 +02:00
@@ -43,7 +43,7 @@ public class BanPlayerCommands {
2023-06-08 03:13:54 +02:00
}, true);
2021-06-15 05:50:26 +02:00
ServerPlayer serverPlayer = source.getServer().getPlayerList().getPlayer(gameProfile.getId());
if (serverPlayer != null) {
2022-06-08 11:31:06 +02:00
- serverPlayer.connection.disconnect(Component.translatable("multiplayer.disconnect.banned"));
+ serverPlayer.connection.disconnect(Component.translatable("multiplayer.disconnect.banned"), org.bukkit.event.player.PlayerKickEvent.Cause.BANNED); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
}
}
diff --git a/src/main/java/net/minecraft/server/commands/KickCommand.java b/src/main/java/net/minecraft/server/commands/KickCommand.java
2023-09-22 19:59:56 +02:00
index c68bac4727f6b2ca95fc8c438303097af14286f2..bb629ec263959c8268de88ca807bddb62e9f877e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/commands/KickCommand.java
+++ b/src/main/java/net/minecraft/server/commands/KickCommand.java
2022-06-08 11:31:06 +02:00
@@ -22,7 +22,7 @@ public class KickCommand {
2021-06-11 14:02:28 +02:00
2021-06-15 05:50:26 +02:00
private static int kickPlayers(CommandSourceStack source, Collection<ServerPlayer> targets, Component reason) {
for(ServerPlayer serverPlayer : targets) {
- serverPlayer.connection.disconnect(reason);
+ serverPlayer.connection.disconnect(reason, org.bukkit.event.player.PlayerKickEvent.Cause.KICK_COMMAND); // Paper - kick event cause
2023-06-08 03:13:54 +02:00
source.sendSuccess(() -> {
return Component.translatable("commands.kick.success", serverPlayer.getDisplayName(), reason);
}, true);
2023-09-22 07:41:27 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2023-10-27 01:34:58 +02:00
index d660041805bcd1bb97cf347d8b1cfe5c65469f56..a0328cfbe4184a2c1dc895e96fa3fefbdc52bf09 100644
2023-09-22 07:41:27 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2023-10-08 12:07:48 +02:00
@@ -94,7 +94,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 07:41:27 +02:00
} else if (!this.isSingleplayerOwner()) {
// Paper start - This needs to be handled on the main thread for plugins
server.submit(() -> {
- this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
+ this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
});
// Paper endg
}
2023-10-08 12:07:48 +02:00
@@ -130,7 +130,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 07:41:27 +02:00
}
} catch (Exception ex) {
ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t register custom payload", ex);
- this.disconnect("Invalid payload REGISTER!");
+ this.disconnect("Invalid payload REGISTER!", org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
2023-10-27 01:34:58 +02:00
} else if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_UNREGISTER)) {
2023-09-22 07:41:27 +02:00
try {
2023-10-08 12:07:48 +02:00
@@ -140,7 +140,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2021-06-11 14:02:28 +02:00
}
2023-09-22 07:41:27 +02:00
} catch (Exception ex) {
ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t unregister custom payload", ex);
- this.disconnect("Invalid payload UNREGISTER!");
+ this.disconnect("Invalid payload UNREGISTER!", org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
} else {
2023-09-22 07:41:27 +02:00
try {
2023-10-08 12:07:48 +02:00
@@ -158,7 +158,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 07:41:27 +02:00
this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data);
} catch (Exception ex) {
ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex);
- this.disconnect("Invalid custom payload!");
+ this.disconnect("Invalid custom payload!", org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause
}
2021-06-11 14:02:28 +02:00
}
2023-10-08 12:07:48 +02:00
@@ -174,7 +174,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 07:41:27 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, (BlockableEventLoop) this.server);
if (packet.getAction() == ServerboundResourcePackPacket.Action.DECLINED && this.server.isResourcePackRequired()) {
ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack rejection", this.playerProfile().getName());
- this.disconnect(Component.translatable("multiplayer.requiredTexturePrompt.disconnect"));
+ this.disconnect(Component.translatable("multiplayer.requiredTexturePrompt.disconnect"), org.bukkit.event.player.PlayerKickEvent.Cause.RESOURCE_PACK_REJECTION); // Paper - kick event cause
}
// Paper start
PlayerResourcePackStatusEvent.Status packStatus = PlayerResourcePackStatusEvent.Status.values()[packet.getAction().ordinal()];
2023-10-08 12:07:48 +02:00
@@ -194,7 +194,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-23 17:50:32 +02:00
if (this.keepAlivePending) {
if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getScoreboardName()); // more info
- this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
+ this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
}
} else {
if (elapsedTime >= 15000L) { // 15 seconds
2023-10-08 12:07:48 +02:00
@@ -247,18 +247,28 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2022-07-29 18:31:02 +02:00
}
2021-06-11 14:02:28 +02:00
2023-09-22 07:41:27 +02:00
// CraftBukkit start
- @Deprecated
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper
public void disconnect(String s) { // Paper
- this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s)); // Paper
+ this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); // Paper
2021-06-11 14:02:28 +02:00
}
2023-09-22 07:41:27 +02:00
// CraftBukkit end
2021-06-11 14:02:28 +02:00
2023-09-22 07:41:27 +02:00
+ // Paper start - kick event cause
2022-07-29 18:31:02 +02:00
+ public void disconnect(String s, PlayerKickEvent.Cause cause) {
+ this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s), cause);
+ }
+
2023-09-22 07:41:27 +02:00
// Paper start
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper
2021-06-11 14:02:28 +02:00
public void disconnect(final Component reason) {
2023-09-22 07:41:27 +02:00
- this.disconnect(io.papermc.paper.adventure.PaperAdventure.asAdventure(reason));
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asAdventure(reason), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN);
2023-06-09 04:51:31 +02:00
+ }
+
+ public void disconnect(final Component reason, PlayerKickEvent.Cause cause) {
2023-09-22 07:41:27 +02:00
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asAdventure(reason), cause);
2021-06-11 14:02:28 +02:00
}
- public void disconnect(net.kyori.adventure.text.Component reason) {
2023-09-22 07:41:27 +02:00
+ public void disconnect(net.kyori.adventure.text.Component reason, org.bukkit.event.player.PlayerKickEvent.Cause cause) { // Paper - kick event cause
2021-06-11 14:02:28 +02:00
// Paper end
// CraftBukkit start - fire PlayerKickEvent
if (this.processedDisconnect) {
2023-10-08 12:07:48 +02:00
@@ -268,7 +278,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2022-12-08 07:11:20 +01:00
Waitable waitable = new Waitable() {
@Override
protected Object evaluate() {
2023-09-22 07:41:27 +02:00
- ServerCommonPacketListenerImpl.this.disconnect(reason); // Paper - adventure
+ ServerCommonPacketListenerImpl.this.disconnect(reason, cause); // Paper - adventure
2022-12-08 07:11:20 +01:00
return null;
}
};
2023-10-08 12:07:48 +02:00
@@ -287,7 +297,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2022-07-27 23:19:52 +02:00
2022-06-09 10:51:45 +02:00
net.kyori.adventure.text.Component leaveMessage = net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? this.player.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(this.player.getScoreboardName())); // Paper - Adventure
2021-06-11 14:02:28 +02:00
2023-09-22 07:41:27 +02:00
- PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), reason, leaveMessage); // Paper - adventure
+ PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), reason, leaveMessage, cause); // Paper - adventure
2021-06-11 14:02:28 +02:00
2021-06-15 05:50:26 +02:00
if (this.cserver.getServer().isRunning()) {
this.cserver.getPluginManager().callEvent(event);
2023-09-22 07:41:27 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-11-11 21:25:45 +01:00
index b35f4ab4ff034f7b59f3970fc18af2f777ec2a40..ef1af985927b1291ccee1ff4f9dbd4fb556bdee6 100644
2023-09-22 07:41:27 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -340,7 +340,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
if (this.clientIsFloating && !this.player.isSleeping() && !this.player.isPassenger() && !this.player.isDeadOrDying()) {
if (++this.aboveGroundTickCount > 80) {
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked for floating too long!", this.player.getName().getString());
- this.disconnect(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.flyingPlayer); // Paper - use configurable kick message
+ this.disconnect(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.flyingPlayer, org.bukkit.event.player.PlayerKickEvent.Cause.FLYING_PLAYER); // Paper - use configurable kick message & kick event cause
return;
}
} else {
@@ -359,7 +359,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
if (this.clientVehicleIsFloating && this.player.getRootVehicle().getControllingPassenger() == this.player) {
if (++this.aboveGroundVehicleTickCount > 80) {
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked for floating a vehicle too long!", this.player.getName().getString());
- this.disconnect(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.flyingVehicle); // Paper - use configurable kick message
+ this.disconnect(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.flyingVehicle, org.bukkit.event.player.PlayerKickEvent.Cause.FLYING_VEHICLE); // Paper - use configurable kick message & kick event cause
return;
}
} else {
@@ -390,7 +390,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) {
this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
- this.disconnect(Component.translatable("multiplayer.disconnect.idling"));
+ this.disconnect(Component.translatable("multiplayer.disconnect.idling"), org.bukkit.event.player.PlayerKickEvent.Cause.IDLING); // Paper - kick event cause
}
}
@@ -460,7 +460,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
public void handleMoveVehicle(ServerboundMoveVehiclePacket packet) {
2023-06-08 03:13:54 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
2021-06-15 05:50:26 +02:00
if (ServerGamePacketListenerImpl.containsInvalidValues(packet.getX(), packet.getY(), packet.getZ(), packet.getYRot(), packet.getXRot())) {
2022-06-08 11:31:06 +02:00
- this.disconnect(Component.translatable("multiplayer.disconnect.invalid_vehicle_movement"));
+ this.disconnect(Component.translatable("multiplayer.disconnect.invalid_vehicle_movement"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_VEHICLE_MOVEMENT); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
} else {
Entity entity = this.player.getRootVehicle();
2023-09-22 07:41:27 +02:00
@@ -666,7 +666,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-06-08 03:13:54 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
2022-07-29 18:31:02 +02:00
if (packet.getId() == this.awaitingTeleport) {
if (this.awaitingPositionFromClient == null) {
- this.disconnect(Component.translatable("multiplayer.disconnect.invalid_player_movement"));
+ this.disconnect(Component.translatable("multiplayer.disconnect.invalid_player_movement"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PLAYER_MOVEMENT); // Paper - kick event cause
return;
}
2023-11-11 21:25:45 +01:00
@@ -724,7 +724,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-06-08 03:13:54 +02:00
// PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - run this async
2021-06-11 14:02:28 +02:00
// CraftBukkit start
2022-06-09 10:51:45 +02:00
if (this.chatSpamTickCount.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper start - split and make configurable
2022-06-08 11:31:06 +02:00
- server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", new Object[0]))); // Paper
+ server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
return;
}
2023-09-22 22:13:57 +02:00
// Paper start
2023-11-11 21:25:45 +01:00
@@ -883,7 +883,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
// Paper start - validate pick item position
2021-06-15 05:50:26 +02:00
if (!(packet.getSlot() >= 0 && packet.getSlot() < this.player.getInventory().items.size())) {
2021-06-11 14:02:28 +02:00
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
- this.disconnect("Invalid hotbar selection (Hacking?)");
+ this.disconnect("Invalid hotbar selection (Hacking?)", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); // Paper - kick event cause
return;
}
2021-06-15 05:50:26 +02:00
this.player.getInventory().pickSlot(packet.getSlot()); // Paper - Diff above if changed
2023-11-11 21:25:45 +01:00
@@ -1066,7 +1066,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
if (byteLength > 256 * 4) {
ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send a book with with a page too large!");
- server.scheduleOnMain(() -> this.disconnect("Book too large!"));
+ server.scheduleOnMain(() -> this.disconnect("Book too large!", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION)); // Paper - kick event cause
return;
}
byteTotal += byteLength;
2023-11-11 21:25:45 +01:00
@@ -1089,14 +1089,14 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
if (byteTotal > byteAllowed) {
ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
- server.scheduleOnMain(() -> this.disconnect("Book too large!"));
+ server.scheduleOnMain(() -> this.disconnect("Book too large!", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION)); // Paper - kick event cause
return;
}
}
// Paper end
// CraftBukkit start
if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
- this.disconnect("Book edited too quickly!");
+ this.disconnect("Book edited too quickly!", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); // Paper - kick event cause
return;
}
this.lastBookTick = MinecraftServer.currentTick;
2023-11-11 21:25:45 +01:00
@@ -1220,7 +1220,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
public void handleMovePlayer(ServerboundMovePlayerPacket packet) {
2023-06-08 03:13:54 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
2021-06-15 05:50:26 +02:00
if (ServerGamePacketListenerImpl.containsInvalidValues(packet.getX(0.0D), packet.getY(0.0D), packet.getZ(0.0D), packet.getYRot(0.0F), packet.getXRot(0.0F))) {
2022-06-08 11:31:06 +02:00
- this.disconnect(Component.translatable("multiplayer.disconnect.invalid_player_movement"));
2022-07-29 18:31:02 +02:00
+ this.disconnect(Component.translatable("multiplayer.disconnect.invalid_player_movement"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PLAYER_MOVEMENT); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
} else {
2023-06-08 03:13:54 +02:00
ServerLevel worldserver = this.player.serverLevel();
2021-06-11 14:02:28 +02:00
2023-11-11 21:25:45 +01:00
@@ -1634,7 +1634,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
this.dropCount++;
if (this.dropCount >= 20) {
2021-06-15 05:50:26 +02:00
ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " dropped their items too quickly!");
2021-06-11 14:02:28 +02:00
- this.disconnect("You dropped your items too quickly (Hacking?)");
+ this.disconnect("You dropped your items too quickly (Hacking?)", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); // Paper - kick event cause
return;
}
}
2023-11-11 21:25:45 +01:00
@@ -1917,7 +1917,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
this.player.resetLastActionTime();
} else {
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
- this.disconnect("Invalid hotbar selection (Hacking?)"); // CraftBukkit
+ this.disconnect("Invalid hotbar selection (Hacking?)", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); // CraftBukkit // Paper - kick event cause
}
}
2023-11-11 21:25:45 +01:00
@@ -1930,7 +1930,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-15 05:50:26 +02:00
}
2022-06-08 11:31:06 +02:00
// CraftBukkit end
2022-07-27 23:19:52 +02:00
if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.message())) {
2022-06-08 11:31:06 +02:00
- this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"));
+ this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - add cause
} else {
2022-12-07 21:16:54 +01:00
Optional<LastSeenMessages> optional = this.tryHandleChat(packet.message(), packet.timeStamp(), packet.lastSeenMessages());
2023-11-11 21:25:45 +01:00
@@ -1963,7 +1963,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-07-29 18:31:02 +02:00
@Override
public void handleChatCommand(ServerboundChatCommandPacket packet) {
if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.command())) {
- this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"));
+ this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper
} else {
2022-12-07 21:16:54 +01:00
Optional<LastSeenMessages> optional = this.tryHandleChat(packet.command(), packet.timeStamp(), packet.lastSeenMessages());
2023-11-11 21:25:45 +01:00
@@ -2018,7 +2018,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-12-08 18:06:14 +01:00
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
if (exception.shouldDisconnect()) {
- this.disconnect(exception.getComponent());
+ this.disconnect(exception.getComponent(), exception.kickCause); // Paper - kick event causes
} else {
this.player.sendSystemMessage(exception.getComponent().copy().withStyle(ChatFormatting.RED));
}
2023-11-11 21:25:45 +01:00
@@ -2049,7 +2049,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-12-07 21:16:54 +01:00
private Optional<LastSeenMessages> tryHandleChat(String message, Instant timestamp, LastSeenMessages.Update acknowledgment) {
2022-07-29 18:31:02 +02:00
if (!this.updateChatOrder(timestamp)) {
ServerGamePacketListenerImpl.LOGGER.warn("{} sent out-of-order chat: '{}'", this.player.getName().getString(), message);
- this.disconnect(Component.translatable("multiplayer.disconnect.out_of_order_chat"));
2023-09-17 00:54:33 +02:00
+ this.disconnect(Component.translatable("multiplayer.disconnect.out_of_order_chat"), org.bukkit.event.player.PlayerKickEvent.Cause.OUT_OF_ORDER_CHAT); // Paper - kick event causes
2022-12-07 21:16:54 +01:00
return Optional.empty();
2023-03-14 21:25:13 +01:00
} else {
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(acknowledgment);
2023-11-11 21:25:45 +01:00
@@ -2072,7 +2072,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-12-08 18:06:14 +01:00
if (optional.isEmpty()) {
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
- this.disconnect(ServerGamePacketListenerImpl.CHAT_VALIDATION_FAILED);
+ this.disconnect(ServerGamePacketListenerImpl.CHAT_VALIDATION_FAILED, org.bukkit.event.player.PlayerKickEvent.Cause.CHAT_VALIDATION_FAILED); // Paper - kick event causes
}
return optional;
2023-11-11 21:25:45 +01:00
@@ -2268,7 +2268,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-07-27 23:19:52 +02:00
// this.chatSpamTickCount += 20;
if (this.chatSpamTickCount.addAndGet(20) > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
2022-06-08 11:31:06 +02:00
// CraftBukkit end
2022-07-27 23:19:52 +02:00
- this.disconnect(Component.translatable("disconnect.spam"));
+ this.disconnect(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause
2022-06-08 11:31:06 +02:00
}
2022-07-27 23:19:52 +02:00
}
2023-11-11 21:25:45 +01:00
@@ -2280,7 +2280,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-12-08 18:06:14 +01:00
synchronized (this.lastSeenMessages) {
if (!this.lastSeenMessages.applyOffset(packet.offset())) {
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
- this.disconnect(ServerGamePacketListenerImpl.CHAT_VALIDATION_FAILED);
+ this.disconnect(ServerGamePacketListenerImpl.CHAT_VALIDATION_FAILED, org.bukkit.event.player.PlayerKickEvent.Cause.CHAT_VALIDATION_FAILED); // Paper - kick event causes
}
}
2023-11-11 21:25:45 +01:00
@@ -2433,7 +2433,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-07-29 18:31:02 +02:00
}
if (i > 4096) {
- this.disconnect(Component.translatable("multiplayer.disconnect.too_many_pending_chats"));
+ this.disconnect(Component.translatable("multiplayer.disconnect.too_many_pending_chats"), org.bukkit.event.player.PlayerKickEvent.Cause.TOO_MANY_PENDING_CHATS); // Paper - kick event cause
}
}
2023-11-11 21:25:45 +01:00
@@ -2490,7 +2490,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
// Spigot Start
2021-06-15 05:50:26 +02:00
if ( entity == this.player && !this.player.isSpectator() )
2021-06-11 14:02:28 +02:00
{
2023-10-27 01:34:58 +02:00
- this.disconnect( "Cannot interact with self!" );
+ this.disconnect( "Cannot interact with self!" , org.bukkit.event.player.PlayerKickEvent.Cause.SELF_INTERACTION ); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
return;
}
// Spigot End
2023-11-11 21:25:45 +01:00
@@ -2589,7 +2589,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-12-07 21:16:54 +01:00
// CraftBukkit end
2021-06-15 05:50:26 +02:00
}
} else {
2022-06-08 11:31:06 +02:00
- ServerGamePacketListenerImpl.this.disconnect(Component.translatable("multiplayer.disconnect.invalid_entity_attacked"));
+ ServerGamePacketListenerImpl.this.disconnect(Component.translatable("multiplayer.disconnect.invalid_entity_attacked"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_ENTITY_ATTACKED); // Paper - add cause
2021-06-15 05:50:26 +02:00
ServerGamePacketListenerImpl.LOGGER.warn("Player {} tried to attack an invalid entity", ServerGamePacketListenerImpl.this.player.getName().getString());
}
2021-06-11 14:02:28 +02:00
}
2023-11-11 21:25:45 +01:00
@@ -2998,7 +2998,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
// Paper start
2021-06-15 05:50:26 +02:00
if (!org.bukkit.Bukkit.isPrimaryThread()) {
2023-06-08 03:13:54 +02:00
if (this.recipeSpamPackets.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamLimit) {
- this.server.scheduleOnMain(() -> this.disconnect(net.minecraft.network.chat.Component.translatable("disconnect.spam", new Object[0]))); // Paper
+ this.server.scheduleOnMain(() -> this.disconnect(net.minecraft.network.chat.Component.translatable("disconnect.spam", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
return;
}
}
2023-11-11 21:25:45 +01:00
@@ -3233,7 +3233,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-12-08 18:06:14 +01:00
if (!Objects.equals(profilepublickey_a, profilepublickey_a1)) {
if (profilepublickey_a != null && profilepublickey_a1.expiresAt().isBefore(profilepublickey_a.expiresAt())) {
- this.disconnect(ProfilePublicKey.EXPIRED_PROFILE_PUBLIC_KEY);
+ this.disconnect(ProfilePublicKey.EXPIRED_PROFILE_PUBLIC_KEY, org.bukkit.event.player.PlayerKickEvent.Cause.EXPIRED_PROFILE_PUBLIC_KEY); // Paper - kick event causes
} else {
try {
2023-06-08 03:13:54 +02:00
SignatureValidator signaturevalidator = this.server.getProfileKeySignatureValidator();
2023-11-11 21:25:45 +01:00
@@ -3246,7 +3246,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-09-22 07:41:27 +02:00
this.resetPlayerChatState(remotechatsession_a.validate(this.player.getGameProfile(), signaturevalidator));
2022-12-08 18:06:14 +01:00
} catch (ProfilePublicKey.ValidationException profilepublickey_b) {
ServerGamePacketListenerImpl.LOGGER.error("Failed to validate profile key: {}", profilepublickey_b.getMessage());
- this.disconnect(profilepublickey_b.getComponent());
+ this.disconnect(profilepublickey_b.getComponent(), profilepublickey_b.kickCause); // Paper - kick event causes
}
}
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
2023-11-04 22:11:55 +01:00
index 80e31db0fbcac487f8dec943972204cddd10e161..dd7298c41eee0f9a63416cfd6c5e5519ffde100a 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
2023-11-04 22:11:55 +01:00
@@ -686,7 +686,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
while (iterator.hasNext()) {
entityplayer = (ServerPlayer) iterator.next();
2021-06-15 05:50:26 +02:00
this.save(entityplayer); // CraftBukkit - Force the player's inventory to be saved
2022-06-08 11:31:06 +02:00
- entityplayer.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login"));
+ entityplayer.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.DUPLICATE_LOGIN); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
// Instead of kicking then returning, we need to store the kick reason
2023-11-04 22:11:55 +01:00
@@ -1329,8 +1329,8 @@ public abstract class PlayerList {
2021-06-15 05:50:26 +02:00
// Paper end
2021-06-11 14:02:28 +02:00
// CraftBukkit start - disconnect safely
for (ServerPlayer player : this.players) {
- if (isRestarting) player.connection.disconnect(org.spigotmc.SpigotConfig.restartMessage); else // Paper
- player.connection.disconnect(this.server.server.shutdownMessage()); // CraftBukkit - add custom shutdown message // Paper - Adventure
+ if (isRestarting) player.connection.disconnect(org.spigotmc.SpigotConfig.restartMessage, org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); else // Paper - kick event cause (cause is never used here)
+ player.connection.disconnect(this.server.server.shutdownMessage(), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); // CraftBukkit - add custom shutdown message // Paper - Adventure & KickEventCause (cause is never used here)
}
// CraftBukkit end
2022-12-08 18:06:14 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java b/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java
2023-09-22 19:59:56 +02:00
index 6724d0a1af13e97bc1d3bd94fd43fef742a0deab..20ba0a0c9eae28658888a77dd2170f629bbcb65b 100644
2022-12-08 18:06:14 +01:00
--- a/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java
+++ b/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java
2023-09-22 07:41:27 +02:00
@@ -24,7 +24,7 @@ public record ProfilePublicKey(ProfilePublicKey.Data data) {
2022-12-08 18:06:14 +01:00
2023-09-22 07:41:27 +02:00
public static ProfilePublicKey createValidated(SignatureValidator servicesSignatureVerifier, UUID playerUuid, ProfilePublicKey.Data publicKeyData) throws ProfilePublicKey.ValidationException {
if (!publicKeyData.validateSignature(servicesSignatureVerifier, playerUuid)) {
2022-12-08 18:06:14 +01:00
- throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE);
+ throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE, org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PUBLIC_KEY_SIGNATURE); // Paper - kick event causes
} else {
return new ProfilePublicKey(publicKeyData);
}
2023-09-22 07:41:27 +02:00
@@ -81,8 +81,16 @@ public record ProfilePublicKey(ProfilePublicKey.Data data) {
2022-12-08 18:06:14 +01:00
}
public static class ValidationException extends ThrowingComponent {
+ public final org.bukkit.event.player.PlayerKickEvent.Cause kickCause; // Paper
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper
public ValidationException(Component messageText) {
+ // Paper start
+ this(messageText, org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN);
+ }
+ public ValidationException(Component messageText, org.bukkit.event.player.PlayerKickEvent.Cause kickCause) {
+ // Paper end
super(messageText);
+ this.kickCause = kickCause; // Paper
}
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2023-11-11 21:25:45 +01:00
index 674084fa12cf1f7defd00e64a198e278855668d0..7b7afb768bbc75827cd0a03da568d2a82b16dca7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2023-09-22 22:13:57 +02:00
@@ -586,7 +586,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
org.spigotmc.AsyncCatcher.catchOp("player kick"); // Spigot
2021-06-15 05:50:26 +02:00
if (this.getHandle().connection == null) return;
2021-06-11 14:02:28 +02:00
2021-06-15 05:50:26 +02:00
- this.getHandle().connection.disconnect(message == null ? "" : message);
+ this.getHandle().connection.disconnect(message == null ? "" : message, org.bukkit.event.player.PlayerKickEvent.Cause.PLUGIN); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
// Paper start
2023-09-22 22:13:57 +02:00
@@ -598,10 +598,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2022-06-01 08:20:12 +02:00
2021-06-11 14:02:28 +02:00
@Override
public void kick(final net.kyori.adventure.text.Component message) {
+ kick(message, org.bukkit.event.player.PlayerKickEvent.Cause.PLUGIN);
+ }
+
+ @Override
+ public void kick(net.kyori.adventure.text.Component message, org.bukkit.event.player.PlayerKickEvent.Cause cause) {
org.spigotmc.AsyncCatcher.catchOp("player kick");
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
if (connection != null) {
- connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
+ connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message, cause);
}
}
2021-06-15 05:50:26 +02:00
2023-11-04 21:20:13 +01:00
@@ -660,7 +665,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2023-06-08 03:13:54 +02:00
2023-09-17 00:54:33 +02:00
// Paper start - Improve chat handling
2023-06-08 03:13:54 +02:00
if (ServerGamePacketListenerImpl.isChatMessageIllegal(msg)) {
- this.getHandle().connection.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"));
+ this.getHandle().connection.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - kick event causes
} else {
if (msg.startsWith("/")) {
this.getHandle().connection.handleCommand(msg);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/spigotmc/RestartCommand.java b/src/main/java/org/spigotmc/RestartCommand.java
2023-10-27 01:34:58 +02:00
index 631457374fda492776f4af0515cee2e43a934d2c..da7d5efd76c9ef92e9ce22860fec791890a687be 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/spigotmc/RestartCommand.java
+++ b/src/main/java/org/spigotmc/RestartCommand.java
2023-09-17 00:54:33 +02:00
@@ -73,7 +73,7 @@ public class RestartCommand extends Command
2021-06-11 14:02:28 +02:00
// Kick all players
for ( ServerPlayer p : com.google.common.collect.ImmutableList.copyOf( MinecraftServer.getServer().getPlayerList().players ) )
{
- p.connection.disconnect(SpigotConfig.restartMessage);
+ p.connection.disconnect(SpigotConfig.restartMessage, org.bukkit.event.player.PlayerKickEvent.Cause.RESTART_COMMAND); // Paper - kick event reason (cause is never used))
}
// Give the socket a chance to send the packets
try