Paper/patches/server/0634-Add-PlayerKickEvent-causes.patch

467 lines
33 KiB
Diff
Raw Normal View History

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
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2022-12-07 21:16:54 +01:00
index 13f8b4699c5b3a99715fada2d774469fb5c17363..213033a59be4239f1225286764be83dcc6fbf973 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
2022-12-07 21:16:54 +01:00
@@ -2125,7 +2125,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
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
2022-06-08 11:31:06 +02:00
index 37c6be64f618857abcbdbfe2a1fd58ed4f997a29..19023c0796f0b6d7b4acd4ff8984355ec5b3faa7 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
2022-06-08 11:31:06 +02:00
@@ -61,7 +61,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
2022-06-08 11:31:06 +02:00
index 991d9a2bfd8d577c9c25e559833af9ddf690f1dc..458b9a730a1f629bd605c26a4ec4440e8ee84b1d 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
2022-06-08 11:31:06 +02:00
@@ -42,7 +42,7 @@ public class BanPlayerCommands {
source.sendSuccess(Component.translatable("commands.ban.success", ComponentUtils.getDisplayName(gameProfile), userBanListEntry.getReason()), 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
2022-06-08 11:31:06 +02:00
index 65637a33ba171a4b598f70cd943d24b0ee44a69f..57a9146bf2dee7a60aab16716e25348fad7ba127 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
2022-06-08 11:31:06 +02:00
source.sendSuccess(Component.translatable("commands.kick.success", serverPlayer.getDisplayName(), reason), true);
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
2022-12-07 21:16:54 +01:00
index 96f6eb2b152d1183ee45cb0b77c9c77ae8e03950..5567689b642ca591bacd47d5d613191caee97e3d 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
2022-12-07 21:16:54 +01:00
@@ -362,7 +362,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-03-01 06:43:03 +01:00
if (this.clientIsFloating && !this.player.isSleeping() && !this.player.isPassenger()) {
2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
return;
}
} else {
2022-12-07 21:16:54 +01:00
@@ -381,7 +381,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
return;
}
} else {
2022-12-07 21:16:54 +01:00
@@ -403,7 +403,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-15 05:50:26 +02:00
if (this.keepAlivePending) {
2021-06-11 14:02:28 +02:00
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
2022-06-08 11:31:06 +02:00
- this.disconnect(Component.translatable("disconnect.timeout", new Object[0]));
+ this.disconnect(Component.translatable("disconnect.timeout", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
}
} else {
if (elapsedTime >= 15000L) { // 15 seconds
2022-12-07 21:16:54 +01:00
@@ -433,7 +433,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) (this.server.getPlayerIdleTimeout() * 1000 * 60)) {
this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
2022-06-08 11:31:06 +02:00
- 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
2021-06-11 14:02:28 +02:00
}
2022-12-07 21:16:54 +01:00
}
@@ -456,16 +456,26 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-29 18:31:02 +02:00
return this.server.isSingleplayerOwner(this.player.getGameProfile());
}
2021-06-11 14:02:28 +02:00
2022-07-29 18:31:02 +02:00
+ @io.papermc.paper.annotation.DoNotUse // Paper
2021-06-11 14:02:28 +02:00
public void disconnect(String s) {
// Paper start
- this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s));
+ this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN);
2021-06-11 14:02:28 +02:00
}
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);
+ }
+
+ @io.papermc.paper.annotation.DoNotUse // Paper
2021-06-11 14:02:28 +02:00
public void disconnect(final Component reason) {
- this.disconnect(PaperAdventure.asAdventure(reason));
+ this.disconnect(PaperAdventure.asAdventure(reason), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN);
}
- public void disconnect(net.kyori.adventure.text.Component reason) {
2022-12-07 21:16:54 +01:00
+ public void disconnect(final Component reason, PlayerKickEvent.Cause cause) {
+ this.disconnect(PaperAdventure.asAdventure(reason), cause);
+ }
+
2021-06-11 14:02:28 +02:00
+ public void disconnect(net.kyori.adventure.text.Component reason, org.bukkit.event.player.PlayerKickEvent.Cause cause) {
// Paper end
// CraftBukkit start - fire PlayerKickEvent
if (this.processedDisconnect) {
2022-12-07 21:16:54 +01:00
@@ -494,7 +504,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-27 23:19:52 +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
2021-06-15 05:50:26 +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 & kick event reason
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);
2022-12-07 21:16:54 +01:00
@@ -564,7 +574,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
public void handleMoveVehicle(ServerboundMoveVehiclePacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
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();
2022-12-07 21:16:54 +01:00
@@ -762,7 +772,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-29 18:31:02 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
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;
}
2022-12-07 21:16:54 +01:00
@@ -819,13 +829,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-06-11 11:02:09 +02:00
// PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); // Paper - run this async
2021-06-11 14:02:28 +02:00
// CraftBukkit start
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;
}
// Paper start
String str = packet.getCommand(); int index = -1;
if (str.length() > 64 && ((index = str.indexOf(' ')) == -1 || index >= 64)) {
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;
}
// Paper end
2022-12-07 21:16:54 +01:00
@@ -978,7 +988,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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
2022-12-07 21:16:54 +01:00
@@ -1165,7 +1175,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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;
2022-12-07 21:16:54 +01:00
@@ -1188,14 +1198,14 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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;
2022-12-07 21:16:54 +01:00
@@ -1319,7 +1329,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
public void handleMovePlayer(ServerboundMovePlayerPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
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 {
ServerLevel worldserver = this.player.getLevel();
2022-12-07 21:16:54 +01:00
@@ -1747,7 +1757,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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;
}
}
2022-12-07 21:16:54 +01:00
@@ -1959,7 +1969,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-15 05:50:26 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (packet.getAction() == ServerboundResourcePackPacket.Action.DECLINED && this.server.isResourcePackRequired()) {
ServerGamePacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getName());
2022-06-08 11:31:06 +02:00
- this.disconnect(Component.translatable("multiplayer.requiredTexturePrompt.disconnect"));
+ this.disconnect(Component.translatable("multiplayer.requiredTexturePrompt.disconnect"), org.bukkit.event.player.PlayerKickEvent.Cause.RESOURCE_PACK_REJECTION); // Paper - add cause
2021-06-15 05:50:26 +02:00
}
// Paper start
PlayerResourcePackStatusEvent.Status packStatus = PlayerResourcePackStatusEvent.Status.values()[packet.action.ordinal()];
2022-12-07 21:16:54 +01:00
@@ -2073,7 +2083,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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
}
}
2022-12-07 21:16:54 +01:00
@@ -2086,7 +2096,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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());
@@ -2120,7 +2130,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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());
@@ -2200,7 +2210,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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"));
2022-12-07 21:16:54 +01:00
+ this.disconnect(Component.translatable("multiplayer.disconnect.out_of_order_chat"), org.bukkit.event.player.PlayerKickEvent.Cause.OUT_OF_ORDER_CHAT); // Paper - kick event ca
return Optional.empty();
2022-07-29 18:31:02 +02:00
} else if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales
this.send(new ClientboundSystemChatPacket(Component.translatable("chat.disabled.options").withStyle(ChatFormatting.RED), false));
2022-12-07 21:16:54 +01:00
@@ -2428,6 +2438,32 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
this.detectRateSpam(s); // Spigot
}
2022-07-29 18:31:02 +02:00
2022-12-07 21:16:54 +01:00
+<<<<<<< HEAD
+=======
+ private boolean verifyChatMessage(PlayerChatMessage message) {
+ ChatSender chatsender = this.player.asChatSender();
+ ProfilePublicKey profilepublickey = chatsender.profilePublicKey();
+
+ if (profilepublickey != null) {
+ if (profilepublickey.data().hasExpired()) {
+ this.player.sendSystemMessage(Component.translatable("chat.disabled.expiredProfileKey").withStyle(ChatFormatting.RED));
+ return false;
+ }
+
+ if (!message.verify(chatsender)) {
2022-08-06 00:58:34 +02:00
+ this.disconnect(Component.translatable("multiplayer.disconnect.unsigned_chat"), org.bukkit.event.player.PlayerKickEvent.Cause.UNSIGNED_CHAT); // Paper - kick event cause
2022-12-07 21:16:54 +01:00
+ return false;
+ }
+ }
+
+ if (message.hasExpiredServer(Instant.now())) {
+ ServerGamePacketListenerImpl.LOGGER.warn("{} sent expired chat: '{}'. Is the client/server system time unsynchronized?", this.player.getName().getString(), message.signedContent().plain());
+ }
+
+ return true;
+ }
+
+>>>>>>> Add PlayerKickEvent causes
// Spigot start - spam exclusions
private void detectRateSpam(String s) {
// CraftBukkit start - replaced with thread safe throttle
@@ -2444,7 +2480,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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
}
2022-12-07 21:16:54 +01:00
@@ -2460,6 +2496,15 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
}
2022-07-29 18:31:02 +02:00
2022-12-07 21:16:54 +01:00
}
+<<<<<<< HEAD
+=======
+
+ }
+
+ private void handleValidationFailure(Set<LastSeenMessagesValidator.ErrorCondition> reasons) {
+ ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message from {}, reasons: {}", this.player.getName().getString(), reasons.stream().map(LastSeenMessagesValidator.ErrorCondition::message).collect(Collectors.joining(",")));
2022-07-29 18:31:02 +02:00
+ this.disconnect(Component.translatable("multiplayer.disconnect.chat_validation_failed"), org.bukkit.event.player.PlayerKickEvent.Cause.CHAT_VALIDATION_FAILED); // Paper - kick event cause
2022-12-07 21:16:54 +01:00
+>>>>>>> Add PlayerKickEvent causes
2022-07-29 18:31:02 +02:00
}
@Override
2022-12-07 21:16:54 +01:00
@@ -2597,7 +2642,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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
}
}
2022-12-07 21:16:54 +01:00
@@ -2621,7 +2666,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
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
{
2021-06-15 05:50:26 +02:00
- this.disconnect( "Cannot interact with self!" );
+ this.disconnect( "Cannot interact with self!", org.bukkit.event.player.PlayerKickEvent.Cause.SELF_INTERACTION ); // Paper - add cause
2021-06-11 14:02:28 +02:00
return;
}
// Spigot End
2022-12-07 21:16:54 +01:00
@@ -2718,7 +2763,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// 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
}
2022-12-07 21:16:54 +01:00
@@ -3126,7 +3171,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
// Paper start
2021-06-15 05:50:26 +02:00
if (!org.bukkit.Bukkit.isPrimaryThread()) {
if (recipeSpamPackets.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamLimit) {
2022-06-08 11:31:06 +02:00
- server.scheduleOnMain(() -> this.disconnect(net.minecraft.network.chat.Component.translatable("disconnect.spam", new Object[0]))); // Paper
+ 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;
}
}
2022-12-07 21:16:54 +01:00
@@ -3334,7 +3379,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
} else if (!this.isSingleplayerOwner()) {
// Paper start - This needs to be handled on the main thread for plugins
2021-06-15 05:50:26 +02:00
server.submit(() -> {
2022-06-08 11:31:06 +02:00
- this.disconnect(Component.translatable("disconnect.timeout"));
+ this.disconnect(Component.translatable("disconnect.timeout"), org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
2021-06-11 14:02:28 +02:00
});
// Paper end
}
2022-12-07 21:16:54 +01:00
@@ -3380,7 +3425,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +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
}
} else if (packet.identifier.equals(CUSTOM_UNREGISTER)) {
try {
2022-12-07 21:16:54 +01:00
@@ -3390,7 +3435,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +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
}
} else {
try {
2022-12-07 21:16:54 +01:00
@@ -3408,7 +3453,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-15 05:50:26 +02:00
this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), packet.identifier.toString(), data);
2021-06-11 14:02:28 +02:00
} 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
}
}
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2022-12-07 21:16:54 +01:00
index 16210f30249ecc83c92e0374f7821693a9fd27c1..20598ef01293d8889145921cb3c5a9c7287b6b23 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
2022-12-07 21:16:54 +01:00
@@ -734,7 +734,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
2022-12-07 21:16:54 +01:00
@@ -1367,8 +1367,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
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2022-12-07 21:16:54 +01:00
index 45ad8545b5b8bf5b1ba0eb5ee2c602b34fc6a138..49501e3cb2e604655f0c6eba38d07855b7632cbf 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
2022-12-07 21:16:54 +01:00
@@ -599,7 +599,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
2022-12-07 21:16:54 +01:00
@@ -611,10 +611,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
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
2021-06-15 05:50:26 +02:00
index 92d97a5810a379b427a99b4c63fb9844d823a84f..160115bf8a153ff981ba308599d22c4c08026fb6 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
@@ -74,7 +74,7 @@ public class RestartCommand extends Command
// 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