Skip to content

Commit

Permalink
Update SGMenuListener.java
Browse files Browse the repository at this point in the history
  • Loading branch information
MCreeper12731 authored Mar 12, 2023
1 parent 97f982b commit 636c0ea
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/com/samjakob/spigui/menu/SGMenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@ public SGMenuListener(JavaPlugin owner, SpiGUI spiGUI) {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {

// Determine if the inventory was a SpiGUI.
if (event.getInventory().getHolder() != null
&& event.getInventory().getHolder() instanceof SGMenu) {
// Determine if the clicked inventory was a SpiGUI.
if (event.getClickedInventory() != null
&& event.getClickedInventory().getHolder() != null
&& event.getClickedInventory().getHolder() instanceof SGMenu) {

// Get the instance of the SpiGUI that was clicked.
SGMenu clickedGui = (SGMenu) event.getInventory().getHolder();
SGMenu clickedGui = (SGMenu) event.getClickedInventory().getHolder();

// Check if the GUI is owner by the current plugin
// (if not, it'll be deferred to the SGMenuListener registered
// by that plugin that does own the GUI.)
if (!clickedGui.getOwner().equals(owner)) return;

//Check if the click was inside the GUI and not inside player's inventory.
// (if not, it will ignore the click)
if (event.getClickedInventory() == null || event.getClickedInventory().getType() == InventoryType.PLAYER) return;

// If the default action is to cancel the event (block default interactions)
// we'll do that now.
Expand Down

0 comments on commit 636c0ea

Please sign in to comment.