From ef8d072daa3414c574ee62d8f3d7f34d511fd7f5 Mon Sep 17 00:00:00 2001 From: Jurjen Verbruggen Date: Sun, 23 Jun 2024 21:50:23 +0200 Subject: [PATCH] Added closing check for inventories and menu sessions --- .../menu/button/event/ButtonClickEventListener.java | 6 +++++- .../java/com/jverbruggen/jrides/models/menu/BaseMenu.java | 6 ++++++ src/main/java/com/jverbruggen/jrides/models/menu/Menu.java | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jverbruggen/jrides/control/uiinterface/menu/button/event/ButtonClickEventListener.java b/src/main/java/com/jverbruggen/jrides/control/uiinterface/menu/button/event/ButtonClickEventListener.java index 0d67e99..96a2556 100644 --- a/src/main/java/com/jverbruggen/jrides/control/uiinterface/menu/button/event/ButtonClickEventListener.java +++ b/src/main/java/com/jverbruggen/jrides/control/uiinterface/menu/button/event/ButtonClickEventListener.java @@ -107,6 +107,10 @@ private void onItemTowardsMenu(InventoryInteractEvent event, Inventory destinati @EventHandler public void onClose(InventoryCloseEvent event){ Player player = playerManager.getPlayer((org.bukkit.entity.Player) event.getPlayer()); - menuSessionManager.removeOpenMenu(player); + Menu menu = menuSessionManager.getOpenMenu(player); + + if(menu.matchesInventory(event.getView())){ + menuSessionManager.removeOpenMenu(player); + } } } diff --git a/src/main/java/com/jverbruggen/jrides/models/menu/BaseMenu.java b/src/main/java/com/jverbruggen/jrides/models/menu/BaseMenu.java index 91e7ae6..9e0ccd7 100644 --- a/src/main/java/com/jverbruggen/jrides/models/menu/BaseMenu.java +++ b/src/main/java/com/jverbruggen/jrides/models/menu/BaseMenu.java @@ -20,6 +20,7 @@ import com.jverbruggen.jrides.api.JRidesPlayer; import org.bukkit.Bukkit; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import java.util.HashMap; import java.util.Map; @@ -60,6 +61,11 @@ public Inventory getInventoryFor(JRidesPlayer player){ return inventory; } + @Override + public boolean matchesInventory(InventoryView inventoryView) { + return inventoryView.getTitle().equalsIgnoreCase(inventoryTitle); + } + @Override public Menu addButton(MenuButton button) { buttons.put(button.getUuid(), button); diff --git a/src/main/java/com/jverbruggen/jrides/models/menu/Menu.java b/src/main/java/com/jverbruggen/jrides/models/menu/Menu.java index 0279121..0d2aa9e 100644 --- a/src/main/java/com/jverbruggen/jrides/models/menu/Menu.java +++ b/src/main/java/com/jverbruggen/jrides/models/menu/Menu.java @@ -20,6 +20,7 @@ import com.jverbruggen.jrides.api.JRidesPlayer; import com.jverbruggen.jrides.models.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import java.util.Map; import java.util.UUID; @@ -30,6 +31,7 @@ public interface Menu { void removeSession(JRidesPlayer player); Inventory getInventoryFor(JRidesPlayer player); + boolean matchesInventory(InventoryView inventoryView); Menu addButton(MenuButton button); MenuButton getButton(UUID buttonUUID); void sendUpdate();