From 9dd1e256428e7fbcc561607f692dcdf0f928bc49 Mon Sep 17 00:00:00 2001 From: Zarkrey <63103822+Zarkreyy@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:26:08 +0100 Subject: [PATCH 1/2] Update EssentialsPlayerListener.java -> handlePlayerCommandPreprocess() no need to recreate a HashMap instance to prevent concurrency since user.getCommandCooldowns() already makes a new HashMap instance the second if condition verifying entry.getValue() > System.currentTimeMillis() is redundant as it is already implied by the first if condition Don't break in case there are other command cooldowns left to clear --- .../essentials/EssentialsPlayerListener.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 1c40363d2e5..7345d98b0e9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -705,21 +705,17 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve // If so, no need to check for (and write) new ones. boolean cooldownFound = false; - // Iterate over a copy of getCommandCooldowns in case of concurrent modifications - for (final Entry entry : new HashMap<>(user.getCommandCooldowns()).entrySet()) { + for (final Entry entry : user.getCommandCooldowns().entrySet()) { // Remove any expired cooldowns if (entry.getValue() <= System.currentTimeMillis()) { user.clearCommandCooldown(entry.getKey()); // Don't break in case there are other command cooldowns left to clear. } else if (entry.getKey().matcher(fullCommand).matches()) { // User's current cooldown hasn't expired, inform and terminate cooldown code. - if (entry.getValue() > System.currentTimeMillis()) { - final String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue()); - user.sendTl("commandCooldown", commandCooldownTime); - cooldownFound = true; - event.setCancelled(true); - break; - } + final String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue()); + user.sendTl("commandCooldown", commandCooldownTime); + cooldownFound = true; + event.setCancelled(true); } } From 63007e61c98eda0523c055b12a994fb042cbf0ea Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:53:23 -0500 Subject: [PATCH 2/2] Remove unused HashMap import --- .../java/com/earth2me/essentials/EssentialsPlayerListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 7345d98b0e9..e6b5043e079 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -65,7 +65,6 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List;