Skip to content

Commit

Permalink
Optimize afk cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Mar 15, 2024
1 parent 10f8780 commit 0354c1c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions patches/server/0074-Improve-Purpur-AFK-system.patch
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ index 9950580f3d0387b142576bfdb6a8f74365c12878..9b87e62426f8805247b86eef0fe2939c
} else {
getBukkitEntity().setPlayerListName(prefix + scoreboardName + suffix);
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index d3a31ca2b926fe809d84cc8b28767c1c69896fe4..8c35a1a612eaa866f4ce4e23e3c0eaf3ce8f491c 100644
index d3a31ca2b926fe809d84cc8b28767c1c69896fe4..a02aa96200eba1012a26d6f4370a6eb9ad738a03 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2264,8 +2264,32 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -2264,8 +2264,33 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}
}

+ private Map<ServerPlayer, Long> cooldown = new java.util.concurrent.ConcurrentHashMap<>(); // Purpur
+ private final Map<UUID, Long> cooldown = new java.util.concurrent.ConcurrentHashMap<>(); // Purpur
+
@Override
public void handleChatCommand(ServerboundChatCommandPacket packet) {
Expand All @@ -58,13 +58,14 @@ index d3a31ca2b926fe809d84cc8b28767c1c69896fe4..8c35a1a612eaa866f4ce4e23e3c0eaf3
+ player.commandAfkStatus = player.isAfk();
+ player.isCommandAfk = true;
+ if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) {
+ UUID uuid = player.getUUID();
+ long currentTime = System.nanoTime();
+ if (cooldown.containsKey(player) && (currentTime - cooldown.get(player)) / 1000000000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) {
+ if (cooldown.containsKey(uuid) && (currentTime - cooldown.get(uuid)) / 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 - (currentTime - cooldown.get(player)) / 1000000000))));
+ 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 - cooldown.get(uuid)) / 1000000000))));
+ return;
+ } else {
+ cooldown.put(player, currentTime);
+ cooldown.put(uuid, currentTime);
+ }
+ // Dreeam - is this necessary?
+ /*
Expand Down

0 comments on commit 0354c1c

Please sign in to comment.