From f7389882c6b56df5f970b649c630032f54c7bc41 Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 1 Jan 2025 19:56:15 +0100 Subject: [PATCH] improve enable/disable of swapitemdelay --- .../aef/modules/combat/SilentSwapDelay.java | 23 +++++++++---------- .../aef/modules/combat/SilentSwapDelay.java | 14 +++++++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java index 07df4e81..64d80945 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java @@ -22,35 +22,34 @@ public class SilentSwapDelay extends AEFModule implements Listener { - private final Map swapItemCooldowns; private final long cooldownNanos; private final boolean updateInventory; + private Map swapItemCooldowns; + public SilentSwapDelay() { super("combat.silent-swap-delay", false); - this.swapItemCooldowns = new ConcurrentHashMap<>(); this.updateInventory = config.getBoolean(configPath + ".update-inventory-on-cancel", false, "Can help with desync but recommended to leave off unless you have issues."); - this.cooldownNanos = TimeUnit.MILLISECONDS.toNanos( - config.getLong(configPath + ".min-swap-delay-millis", 40L,""" - The delay in millis a player cant swap hotbar items after placing - a block, clicking a block (for example to place a crystal) or - damaging an entity. (50 ms = 1 tick)""")); + this.cooldownNanos = TimeUnit.MILLISECONDS.toNanos(config.getLong(configPath + ".min-swap-delay-millis", 40L,""" + The delay in millis a player cant swap hotbar items after placing + a block, clicking a block (for example to place a crystal) or + damaging an entity. (50 ms = 1 tick)""")); } @Override public void enable() { + swapItemCooldowns = new ConcurrentHashMap<>(); plugin.getServer().getPluginManager().registerEvents(this, plugin); } - @Override - public boolean shouldEnable() { - return config.getBoolean(configPath + ".enable", false); - } - @Override public void disable() { HandlerList.unregisterAll(this); + if (swapItemCooldowns != null) { + swapItemCooldowns.clear(); + swapItemCooldowns = null; + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java index 573205ff..89c87547 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.java @@ -22,30 +22,34 @@ public class SilentSwapDelay extends AEFModule implements Listener { - private final Map swapItemCooldowns; private final long cooldownNanos; private final boolean updateInventory; + private Map swapItemCooldowns; + public SilentSwapDelay() { super("combat.silent-swap-delay", false); - this.swapItemCooldowns = new ConcurrentHashMap<>(); this.updateInventory = config.getBoolean(configPath + ".update-inventory-on-cancel", false, "Can help with desync but recommended to leave off unless you have issues."); - this.cooldownNanos = TimeUnit.MILLISECONDS.toNanos( - config.getLong(configPath + ".min-swap-delay-millis", 40L, - "The delay in millis a player cant swap hotbar items after placing\n" + + this.cooldownNanos = TimeUnit.MILLISECONDS.toNanos(config.getLong(configPath + ".min-swap-delay-millis", 40L, + "The delay in millis a player cant swap hotbar items after placing\n" + "a block, clicking a block (for example to place a crystal) or\n" + "damaging an entity. (50 ms = 1 tick)")); } @Override public void enable() { + swapItemCooldowns = new ConcurrentHashMap<>(); plugin.getServer().getPluginManager().registerEvents(this, plugin); } @Override public void disable() { HandlerList.unregisterAll(this); + if (swapItemCooldowns != null) { + swapItemCooldowns.clear(); + swapItemCooldowns = null; + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)