From d233f6bfd8c4329c5165648dfdf7ee8b2c094dac Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Sat, 21 Sep 2024 02:21:38 -0400 Subject: [PATCH] Update, cleanup Purpur afk improvement patch & Fix cooldown bypass issue for signed chat command --- .../0065-Improve-Purpur-AFK-system.patch | 129 +++++++++++++----- ...specified-item-components-to-clients.patch | 4 +- 2 files changed, 98 insertions(+), 35 deletions(-) diff --git a/patches/server/0065-Improve-Purpur-AFK-system.patch b/patches/server/0065-Improve-Purpur-AFK-system.patch index fc80ca348..4cb78b9bf 100644 --- a/patches/server/0065-Improve-Purpur-AFK-system.patch +++ b/patches/server/0065-Improve-Purpur-AFK-system.patch @@ -7,34 +7,37 @@ AFK command & command cooldown AFK title message diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index b6713361cd104786f52bd880418b8653e4126fda..94bb40c9932b0b7dd9fb8af680b63d139ae18e3a 100644 +index b6713361cd104786f52bd880418b8653e4126fda..11e94766b487ee8e112813cae0561b84d16f4f8a 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java @@ -246,6 +246,7 @@ public class Commands { StopCommand.register(this.dispatcher); TransferCommand.register(this.dispatcher); WhitelistCommand.register(this.dispatcher); -+ org.purpurmc.purpur.command.AFKCommand.register(this.dispatcher); // Purpur ++ org.purpurmc.purpur.command.AFKCommand.register(this.dispatcher); // Leaf - Improve Purpur AFK system org.purpurmc.purpur.command.CreditsCommand.register(this.dispatcher); // Purpur org.purpurmc.purpur.command.DemoCommand.register(this.dispatcher); // Purpur org.purpurmc.purpur.command.PingCommand.register(this.dispatcher); // Purpur diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java -index 7c6bda95b8b08cc70182f19cf0b991f78d28c235..9fb0372511710cb27ffb18f9879e3ff3a0384427 100644 +index 7c6bda95b8b08cc70182f19cf0b991f78d28c235..79df52237b7a5822e0cbaff015ccd193a8195980 100644 --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java -@@ -2414,6 +2414,8 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple +@@ -2414,6 +2414,10 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple // Purpur Start private boolean isAfk = false; ++ // Leaf sart - Improve Purpur AFK system + public boolean isCommandAfk = false; + public boolean commandAfkStatus = false; ++ // Leaf end - Improve Purpur AFK system @Override public void setAfk(boolean afk) { -@@ -2451,6 +2453,20 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple +@@ -2451,6 +2455,22 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple String prefix = (split.length > 0 ? split[0] : "").replace(org.purpurmc.purpur.PurpurConfig.afkTabListPrefix, ""); String suffix = (split.length > 1 ? split[1] : "").replace(org.purpurmc.purpur.PurpurConfig.afkTabListSuffix, ""); if (afk) { ++ // Leaf start - Improve Purpur AFK system + String[] rawTitle = org.purpurmc.purpur.PurpurConfig.afkTitleAway.split(":"); + if (rawTitle.length == 5) { + String title = rawTitle[0]; @@ -48,91 +51,148 @@ index 7c6bda95b8b08cc70182f19cf0b991f78d28c235..9fb0372511710cb27ffb18f9879e3ff3 + LOGGER.error("You put wrong format of afk-title-away in PurpurConfig, it should look like AFK:You are now AFK...:10:70:20"); + LOGGER.error("'Title:Sub Title:Title Fade In Ticks:Title Stay Ticks:Title Fade Out Ticks', split with :"); + } ++ // Leaf end - Improve Purpur AFK system + getBukkitEntity().setPlayerListName(org.purpurmc.purpur.PurpurConfig.afkTabListPrefix + prefix + scoreboardName + suffix + org.purpurmc.purpur.PurpurConfig.afkTabListSuffix, true); } else { getBukkitEntity().setPlayerListName(prefix + scoreboardName + suffix, true); diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 33b2234970e3b78ccd4b8da184bbdd62b50d3afa..81b0f8c986131335533f6c81f9150b8c6019f8d7 100644 +index 33b2234970e3b78ccd4b8da184bbdd62b50d3afa..4cf8e0a2817795cc3c4ed30a0bf1199dd0e40c83 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -2276,8 +2276,28 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2276,6 +2276,8 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl } } -+ public static final Map afkCooldown = new java.util.concurrent.ConcurrentHashMap<>(); // Purpur ++ public static final Map afkCooldown = new java.util.concurrent.ConcurrentHashMap<>(); // Leaf - Improve Purpur AFK system + @Override public void handleChatCommand(ServerboundChatCommandPacket packet) { -+ // Purpur start -+ if (this.server.getPlayerIdleTimeout() > 0 && packet.command().equals("afk")) { -+ player.commandAfkStatus = player.isAfk(); -+ player.isCommandAfk = true; + this.tryHandleChat(packet.command(), () -> { +@@ -2296,6 +2298,32 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl + ServerGamePacketListenerImpl.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + command1); + } + ++ // Leaf start - Improve Purpur AFK system ++ if (command.equals("afk")) { ++ this.player.commandAfkStatus = this.player.isAfk(); ++ this.player.isCommandAfk = true; ++ + if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) { -+ UUID uuid = player.getUUID(); ++ UUID uuid = this.player.getUUID(); ++ Long cooldown = afkCooldown.get(uuid); + long currentTime = System.nanoTime(); -+ if (afkCooldown.containsKey(uuid) && (currentTime - afkCooldown.get(uuid)) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) { ++ ++ if (cooldown != null && (currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) { + String msg = org.purpurmc.purpur.PurpurConfig.afkCooldown; -+ if (msg != null && !msg.isEmpty()) -+ player.sendMessage(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(msg.replace("%time%", String.valueOf(org.purpurmc.purpur.PurpurConfig.afkCommandCooldown - (currentTime - afkCooldown.get(uuid)) / 1_000_000_000)))); ++ ++ if (msg != null && !msg.isEmpty()) { ++ net.kyori.adventure.text.Component message = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(msg.replace("%time%", String.valueOf(org.purpurmc.purpur.PurpurConfig.afkCommandCooldown - (currentTime - cooldown) / 1_000_000_000))); ++ this.player.sendMessage(message); ++ } ++ + return; + } else { + afkCooldown.put(uuid, currentTime); + } + } + } -+ // Purpur end - this.tryHandleChat(packet.command(), () -> { - // CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands - if (this.player.hasDisconnected()) { ++ // Leaf end - Improve Purpur AFK system ++ + PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(this.getCraftPlayer(), command1, new LazyPlayerSet(this.server)); + this.cserver.getPluginManager().callEvent(event); + +@@ -2333,11 +2361,37 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl + + private void performSignedChatCommand(ServerboundChatCommandSignedPacket packet, LastSeenMessages lastSeenMessages) { + // CraftBukkit start +- String command = "/" + packet.command(); ++ String command = "/" + packet.command(); // Leaf start - Improve Purpur AFK system - diff on change + if (org.spigotmc.SpigotConfig.logCommands) { // Paper - Add missing SpigotConfig logCommands check + ServerGamePacketListenerImpl.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + command); + } // Paper - Add missing SpigotConfig logCommands check + ++ // Leaf start - Improve Purpur AFK system ++ if (command.equals("/afk")) { ++ this.player.commandAfkStatus = this.player.isAfk(); ++ this.player.isCommandAfk = true; ++ ++ if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) { ++ UUID uuid = this.player.getUUID(); ++ Long cooldown = afkCooldown.get(uuid); ++ long currentTime = System.nanoTime(); ++ ++ if (cooldown != null && (currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) { ++ String msg = org.purpurmc.purpur.PurpurConfig.afkCooldown; ++ ++ if (msg != null && !msg.isEmpty()) { ++ net.kyori.adventure.text.Component message = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(msg.replace("%time%", String.valueOf(org.purpurmc.purpur.PurpurConfig.afkCommandCooldown - (currentTime - cooldown) / 1_000_000_000))); ++ this.player.sendMessage(message); ++ } ++ ++ return; ++ } else { ++ afkCooldown.put(uuid, currentTime); ++ } ++ } ++ } ++ // Leaf end - Improve Purpur AFK system ++ + PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(this.getCraftPlayer(), command, new LazyPlayerSet(this.server)); + this.cserver.getPluginManager().callEvent(event); + diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 5cffe034571ef1ddf868d22fc38b1a8c2a1500f1..714e0bf56ee866b4ba00953074bec9642cc5f08e 100644 +index f073b87e6b214e08672980f8f229cd436a742def..5d81f06c981128e4199555c1378345dccf4682b2 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -759,6 +759,7 @@ public abstract class PlayerList { org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(entityplayer); // Leaves - protocol // Paper end - Fix kick event leave message not being sent org.purpurmc.purpur.task.BossBarTask.removeFromAll(entityplayer.getBukkitEntity()); // Purpur -+ net.minecraft.server.network.ServerGamePacketListenerImpl.afkCooldown.remove(entityplayer.getBukkitEntity().getUniqueId()); // Puprur ++ net.minecraft.server.network.ServerGamePacketListenerImpl.afkCooldown.remove(entityplayer.getBukkitEntity().getUniqueId()); // Leaf - Improve Purpur AFK system ServerLevel worldserver = entityplayer.serverLevel(); entityplayer.awardStat(Stats.LEAVE_GAME); diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -index 69832f436254d975a77e251e6ae5de2e81f92750..0715ff8e271400ae59fd533883cc0e7dcee83357 100644 +index 69832f436254d975a77e251e6ae5de2e81f92750..0a6aa10b112cf24a490ac4350f04a65e03fbb692 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -@@ -178,9 +178,12 @@ public class PurpurConfig { +@@ -178,9 +178,14 @@ public class PurpurConfig { public static String cannotRideMob = "You cannot mount that mob"; public static String afkBroadcastAway = "%s is now AFK"; public static String afkBroadcastBack = "%s is no longer AFK"; -+ public static String afkTitleAway = "AFK:You are now AFK...:10:70:20"; ++ public static String afkTitleAway = "AFK:You are now AFK...:10:70:20"; // Leaf - Improve Purpur AFK system public static boolean afkBroadcastUseDisplayName = false; public static String afkTabListPrefix = "[AFK] "; public static String afkTabListSuffix = ""; ++ // Leaf start - Improve Purpur AFK system + public static int afkCommandCooldown = 0; + public static String afkCooldown = "You need to wait %time%s to use /afk."; ++ // Leaf end - Improve Purpur AFK system public static String creditsCommandOutput = "%s has been shown the end credits"; public static String demoCommandOutput = "%s has been shown the demo screen"; public static String pingCommandOutput = "%s's ping is %sms"; -@@ -197,9 +200,12 @@ public class PurpurConfig { +@@ -197,9 +202,14 @@ public class PurpurConfig { cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob); afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway); afkBroadcastBack = getString("settings.messages.afk-broadcast-back", afkBroadcastBack); -+ afkTitleAway = getString("settings.messages.afk-title-away", afkTitleAway); ++ afkTitleAway = getString("settings.messages.afk-title-away", afkTitleAway); // Leaf - Improve Purpur AFK system afkBroadcastUseDisplayName = getBoolean("settings.messages.afk-broadcast-use-display-name", afkBroadcastUseDisplayName); afkTabListPrefix = MiniMessage.miniMessage().serialize(MiniMessage.miniMessage().deserialize(getString("settings.messages.afk-tab-list-prefix", afkTabListPrefix))); afkTabListSuffix = MiniMessage.miniMessage().serialize(MiniMessage.miniMessage().deserialize(getString("settings.messages.afk-tab-list-suffix", afkTabListSuffix))); ++ // Leaf start - Improve Purpur AFK system + afkCommandCooldown = getInt("settings.messages.afk-command-cooldown", afkCommandCooldown); + afkCooldown = MiniMessage.miniMessage().serialize(MiniMessage.miniMessage().deserialize(getString("settings.messages.afk-command-cooldown-msg", afkCooldown))); ++ // Leaf end - Improve Purpur AFK system creditsCommandOutput = getString("settings.messages.credits-command-output", creditsCommandOutput); demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput); pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput); diff --git a/src/main/java/org/purpurmc/purpur/command/AFKCommand.java b/src/main/java/org/purpurmc/purpur/command/AFKCommand.java new file mode 100644 -index 0000000000000000000000000000000000000000..8dca966c25f8e3f5622ef8f5862fdb43eae3813f +index 0000000000000000000000000000000000000000..1b8eee9cce3ae069be7c97bd0840338e9287ce4e --- /dev/null +++ b/src/main/java/org/purpurmc/purpur/command/AFKCommand.java -@@ -0,0 +1,34 @@ +@@ -0,0 +1,37 @@ +package org.purpurmc.purpur.command; + +import com.mojang.brigadier.CommandDispatcher; @@ -158,12 +218,15 @@ index 0000000000000000000000000000000000000000..8dca966c25f8e3f5622ef8f5862fdb43 + + private static int execute(CommandSourceStack sender, Collection targets) { + for (ServerPlayer player : targets) { -+ boolean afk = player.isCommandAfk ? !player.commandAfkStatus : !player.isAfk(); -+ if (afk) { -+ player.setAfk(true); -+ } ++ boolean afk = player.isCommandAfk ++ ? !player.commandAfkStatus ++ : !player.isAfk(); ++ ++ if (afk) player.setAfk(true); ++ + player.isCommandAfk = false; + } ++ + return targets.size(); + } +} diff --git a/patches/server/0096-Hide-specified-item-components-to-clients.patch b/patches/server/0096-Hide-specified-item-components-to-clients.patch index b9153044f..7140c64ad 100644 --- a/patches/server/0096-Hide-specified-item-components-to-clients.patch +++ b/patches/server/0096-Hide-specified-item-components-to-clients.patch @@ -65,10 +65,10 @@ index 573c380e123473e35c0b72c44b32c8d6ba8e61c6..feacc41ecf7f4028e0a1cce5d2012ced } diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 68cc3c4efd7e10a2ddc0576491e9cb5b02fcabe7..5ee48b2347b4d588206d4c4aabd47a3918046973 100644 +index df734f214ecfe798f1b9098e4a068d43ade5680c..b7b204d13663d8da9f0a05a3fcd7eb01860d0412 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -2921,7 +2921,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2955,7 +2955,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl entity.refreshEntityData(ServerGamePacketListenerImpl.this.player); // SPIGOT-7136 - Allays if (entity instanceof Allay || entity instanceof net.minecraft.world.entity.animal.horse.AbstractHorse) { // Paper - Fix horse armor desync