From 245acd69cefafb51005417223acb9c2f6e9d6d14 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Mon, 4 Mar 2024 04:56:20 -0500 Subject: [PATCH] Fix afk command NPE --- patches/server/0072-Improve-Purpur-AFK-system.patch | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/patches/server/0072-Improve-Purpur-AFK-system.patch b/patches/server/0072-Improve-Purpur-AFK-system.patch index f21f95445..a6a433654 100644 --- a/patches/server/0072-Improve-Purpur-AFK-system.patch +++ b/patches/server/0072-Improve-Purpur-AFK-system.patch @@ -56,10 +56,10 @@ 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..0818cd5912852c3ab9cdd999e02caafe1f8b94e0 100644 +index 42885c7f374f619fe63d9fe22a4b7f88d68008c3..a3285a1981a45d19b7b751a3b87e9de4dfb3e47d 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -2264,8 +2264,27 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl +@@ -2264,8 +2264,26 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl } } @@ -73,10 +73,9 @@ index 42885c7f374f619fe63d9fe22a4b7f88d68008c3..0818cd5912852c3ab9cdd999e02caafe + player.isCommandAfk = true; + if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) { + long currentTime = System.nanoTime(); -+ long cd = (currentTime - cooldown.get(player)) / 1000000000; -+ if (cooldown.containsKey(player) && cd <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) { ++ 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 - cd)))); ++ 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)))); + return; + } else { + cooldown.put(player, currentTime);