From c4ccb593c6199143ac4ccad66314b8424b3308db Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Thu, 13 Oct 2022 08:53:50 +0200 Subject: [PATCH] Solved cancellation problem for /deposit GUI. --- .../mmocore/gui/api/PluginInventory.java | 17 +++++++++++++++++ .../Indyuce/mmocore/gui/eco/DepositMenu.java | 2 +- .../mmocore/listener/PlayerListener.java | 9 +++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java index 3b17636a..2bcb52d1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java @@ -8,6 +8,10 @@ import org.bukkit.inventory.InventoryHolder; public abstract class PluginInventory implements InventoryHolder { protected final Player player; protected final PlayerData playerData; + /** + * If all the clicks sould be cancelled for the inventory + */ + private boolean shouldCancel = true; public PluginInventory(PlayerData playerData) { this.playerData = playerData; @@ -19,6 +23,15 @@ public abstract class PluginInventory implements InventoryHolder { this.playerData = player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof PluginInventory ? ((PluginInventory) player.getOpenInventory().getTopInventory().getHolder()).playerData : PlayerData.get(player); } + public PluginInventory(Player player, boolean shouldCancel) { + this(player); + this.shouldCancel=shouldCancel; + } + public PluginInventory(PlayerData playerData, boolean shouldCancel) { + this(playerData); + this.shouldCancel=shouldCancel; + } + public PlayerData getPlayerData() { return playerData; } @@ -27,6 +40,10 @@ public abstract class PluginInventory implements InventoryHolder { return player; } + public boolean shouldCancel() { + return shouldCancel; + } + /** * Opens classic inventory, throws */ diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java index c444cd67..7601a8c8 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java @@ -30,7 +30,7 @@ public class DepositMenu extends PluginInventory { private BukkitRunnable updateRunnable; public DepositMenu(Player player) { - super(player); + super(player,false); } @Override diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index c3f53116..0cdb1cc0 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -38,11 +38,12 @@ public class PlayerListener implements Listener { // Register custom inventory clicks @EventHandler public void b(InventoryClickEvent event) { - if (event.getInventory().getHolder() instanceof PluginInventory) { - event.setCancelled(true); + if (event.getInventory().getHolder() instanceof PluginInventory pluginInventory) { + if (pluginInventory.shouldCancel()) { + event.setCancelled(true); + } if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null) - ((PluginInventory) event.getInventory().getHolder()) - .whenClicked(new InventoryClickContext(event.getRawSlot(), event.getCurrentItem(), event.getClick(), event, event.getInventory())); + pluginInventory.whenClicked(new InventoryClickContext(event.getRawSlot(), event.getCurrentItem(), event.getClick(), event, event.getInventory())); } }