Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a fix to check if the clicked inventory is the GUI and not player's own inventory #20

Merged
merged 3 commits into from
Mar 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/main/java/com/samjakob/spigui/menu/SGMenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ 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;

// If the default action is to cancel the event (block default interactions)
// we'll do that now.
// The inventory's value is checked first, so it can be overridden on a
Expand Down