Skip to content

Commit

Permalink
Ability to track menus during inventory open event
Browse files Browse the repository at this point in the history
  • Loading branch information
instrumentalityi committed Aug 25, 2024
1 parent 754b077 commit 79237a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/gg/saki/zaiko/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public final void open(@NotNull Player player) {
inventory.setItem(i, placeable.getItem());
}

player.openInventory(inventory);

this.zaiko.openMenus.put(player.getUniqueId(), this);

player.openInventory(inventory);
}


Expand Down
21 changes: 20 additions & 1 deletion api/src/main/java/gg/saki/zaiko/MenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
import org.bukkit.Bukkit;
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.*;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -120,4 +124,19 @@ private void onClose(InventoryCloseEvent event) {
// internal close/cleanup
menu.close(player, event.getInventory(), true);
}

@EventHandler(priority = EventPriority.LOWEST)
private void onOpen(InventoryOpenEvent event) {
if (!(event.getPlayer() instanceof Player)) return;

Player player = (Player) event.getPlayer();

Menu menu = this.zaiko.getOpenMenu(player.getUniqueId());

if (menu == null) return;

if(!event.isCancelled()) return;

this.zaiko.openMenus.remove(player.getUniqueId());
}
}

0 comments on commit 79237a0

Please sign in to comment.