From c4d5e3c6d146cc72e089486773388db4875b10a1 Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 21 Aug 2024 03:35:42 +0200 Subject: [PATCH] add option to update inv on cancel --- .../java/me/xginko/aef/modules/combat/SilentSwapDelay.java | 6 ++++++ .../java/me/xginko/aef/modules/combat/SilentSwapDelay.java | 6 ++++++ 2 files changed, 12 insertions(+) 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 479a670b..ce6cd7cd 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 @@ -2,6 +2,7 @@ import com.cryptomorin.xseries.XEntityType; import me.xginko.aef.modules.AEFModule; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -23,10 +24,13 @@ public class SilentSwapDelay extends AEFModule implements Listener { private final Map swapItemCooldowns; private final long cooldownNanos; + private final boolean updateInventory; public SilentSwapDelay() { super("combat.silent-swap-delay"); 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 @@ -55,6 +59,7 @@ private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot b if (swapItemCooldowns.get(event.getPlayer().getUniqueId()) > System.nanoTime()) { event.setCancelled(true); + if (updateInventory) event.getPlayer().updateInventory(); } } @@ -64,6 +69,7 @@ private void onInventoryInteract(InventoryInteractEvent event) { if (swapItemCooldowns.get(event.getWhoClicked().getUniqueId()) > System.nanoTime()) { event.setCancelled(true); + if (updateInventory) ((Player) event.getWhoClicked()).updateInventory(); } } 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 9f42f03a..a22fd3d4 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 @@ -2,6 +2,7 @@ import com.cryptomorin.xseries.XEntityType; import me.xginko.aef.modules.AEFModule; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -23,10 +24,13 @@ public class SilentSwapDelay extends AEFModule implements Listener { private final Map swapItemCooldowns; private final long cooldownNanos; + private final boolean updateInventory; public SilentSwapDelay() { super("combat.silent-swap-delay"); 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" + @@ -55,6 +59,7 @@ private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot b if (swapItemCooldowns.get(event.getPlayer().getUniqueId()) > System.nanoTime()) { event.setCancelled(true); + if (updateInventory) event.getPlayer().updateInventory(); } } @@ -64,6 +69,7 @@ private void onInventoryInteract(InventoryInteractEvent event) { if (swapItemCooldowns.get(event.getWhoClicked().getUniqueId()) > System.nanoTime()) { event.setCancelled(true); + if (updateInventory) ((Player) event.getWhoClicked()).updateInventory(); } }