From 1bc5011d4f8a234465502aea63e565177cf0607b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 8 Apr 2022 13:21:45 +0200 Subject: [PATCH] Prevent ProcessingSpam Signed-off-by: Lixfel --- .../bungeecore/inventory/SWInventory.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index b827e884..0d4a8d30 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; public class SWInventory { @@ -39,6 +40,8 @@ public class SWInventory { private String title; private boolean next; + private final AtomicBoolean processingClick = new AtomicBoolean(); + public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) { itemMap = new HashMap<>(); InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer).getId(), this); @@ -101,13 +104,19 @@ public class SWInventory { } public void handleCallback(InvCallback.ClickType type, int pos) { - itemMap.get(pos).getCallback().clicked(type); + if(processingClick.compareAndSet(false, true)) { + itemMap.get(pos).getCallback().clicked(type); + processingClick.set(false); + } } public void handleClose() { - InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player).getId(), this); - if(close != null) - close.clicked(null); + if(processingClick.compareAndSet(false, true)) { + InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player).getId(), this); + if(close != null) + close.clicked(null); + processingClick.set(false); + } } public void open() {