From f593f17c6a1ba65e4dd7b0c47b19ad5627d611fa Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Mon, 2 Sep 2019 16:29:19 -0500 Subject: [PATCH] prevent gui double-click item move with unlocked cells --- .../java/com/songoda/core/gui/GuiManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/songoda/core/gui/GuiManager.java b/src/main/java/com/songoda/core/gui/GuiManager.java index 9a5dae75..426b3a6f 100644 --- a/src/main/java/com/songoda/core/gui/GuiManager.java +++ b/src/main/java/com/songoda/core/gui/GuiManager.java @@ -9,16 +9,19 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; /** @@ -132,6 +135,7 @@ public class GuiManager { if (!(event.getWhoClicked() instanceof Player)) { return; } + Inventory openInv = event.getInventory(); final Player player = (Player) event.getWhoClicked(); Gui gui; @@ -139,6 +143,20 @@ public class GuiManager { && ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) { gui = ((GuiHolder) openInv.getHolder()).getGUI(); + if (event.getClick() == ClickType.DOUBLE_CLICK) { + // always cancel this event if there are matching gui elements, since it tends to do bad things + ItemStack clicked = event.getCursor(); + if(clicked != null && clicked.getType() != Material.AIR) { + int cell = 0; + for(ItemStack it : gui.inventory.getContents()) { + if(!gui.unlockedCells.getOrDefault(cell++, false) && clicked.isSimilar(it)) { + event.setCancelled(true); + break; + } + } + } + } + if (event.getSlotType() == SlotType.OUTSIDE) { if (!gui.onClickOutside(manager, player, event)) { event.setCancelled(true);