diff --git a/patches/server/0072-Improve-Purpur-AFK-system.patch b/patches/server/0072-Improve-Purpur-AFK-system.patch index 3ef9ee067..7608f1689 100644 --- a/patches/server/0072-Improve-Purpur-AFK-system.patch +++ b/patches/server/0072-Improve-Purpur-AFK-system.patch @@ -4,6 +4,7 @@ Date: Sat, 2 Mar 2024 18:22:15 -0500 Subject: [PATCH] Improve Purpur AFK system Add afk command +Add afk command cooldown Add custom afk tab name diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java @@ -55,27 +56,41 @@ index 9950580f3d0387b142576bfdb6a8f74365c12878..4270b24734affdeff0cd49ab494b7fad } diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 42885c7f374f619fe63d9fe22a4b7f88d68008c3..c7fbf58f0aa653bf4b89fa0787f5ad4ca83e51d5 100644 +index 42885c7f374f619fe63d9fe22a4b7f88d68008c3..08407b2eaacb581085f6c22820304fd179c42af4 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -2266,6 +2266,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2264,8 +2264,26 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl + } + } ++ private final Map cooldown = new java.util.concurrent.ConcurrentHashMap<>(); // Purpur ++ @Override public void handleChatCommand(ServerboundChatCommandPacket packet) { + // Purpur start + if (packet.command().equals("afk")) { + player.commandAfkStatus = player.isAfk(); + player.isCommandAfk = true; ++ long currentTime = System.nanoTime(); ++ if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) { ++ if (cooldown.containsKey(player) && (currentTime - cooldown.get(player)) / 1000000000 <= 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 - cooldown.get(player))))); ++ return; ++ } else { ++ cooldown.put(player, currentTime); ++ } ++ } + } + // Purpur end if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.command())) { this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper } else { diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -index e45c11bf2c42e6d57f803349d8ca6936ac98c995..61dc8b798f1246c19c7e45e9ae9c54366286cfce 100644 +index e45c11bf2c42e6d57f803349d8ca6936ac98c995..9536b0c27f5422161d6bd9fa6916735fa31602f0 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -@@ -176,8 +176,11 @@ public class PurpurConfig { +@@ -176,9 +176,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"; @@ -83,11 +98,15 @@ index e45c11bf2c42e6d57f803349d8ca6936ac98c995..61dc8b798f1246c19c7e45e9ae9c5436 + public static String afkSubTitleAway = "You are now AFK..."; public static boolean afkBroadcastUseDisplayName = false; public static String afkTabListPrefix = "[AFK] "; +- public static String afkTabListSuffix = ""; + public static String afkTabListCustomName = "%player_name% [AFK]"; - public static String afkTabListSuffix = ""; ++ public static String afkTabListSuffix = "You need to wait %time%s to use /afk."; ++ public static long afkCommandCooldown = 3; ++ public static String afkCooldown = ""; public static String creditsCommandOutput = "%s has been shown the end credits"; public static String demoCommandOutput = "%s has been shown the demo screen"; -@@ -197,6 +200,7 @@ public class PurpurConfig { + public static String pingCommandOutput = "%s's ping is %sms"; +@@ -197,6 +202,7 @@ public class PurpurConfig { afkBroadcastBack = getString("settings.messages.afk-broadcast-back", afkBroadcastBack); 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)));