Skip to content

Commit

Permalink
Secured the handling of InventoryClickEvent for panels (#761)
Browse files Browse the repository at this point in the history
* Fix Challenges GUI issue 132

Fixed BentoBoxWorld/Challenges#132
This issue happens because AnvilGUIClick event was processed after BentoBox registers new Panel. 
I add extra check in InventoryClickEvent that not only checks if user has opened panel, but also compares if event and panel has the same inventory, before processing it as BentoBox Panel.

* Removed the unneeded PlayerKickEvent
  • Loading branch information
BONNe authored and Poslovitch committed Jun 14, 2019
1 parent 2e84860 commit ebe2f5a
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.inventory.InventoryView;
Expand All @@ -31,7 +32,8 @@ public void onInventoryClick(InventoryClickEvent event) {
InventoryView view = event.getView();

// Open the inventory panel that this player has open (they can only ever have one)
if (openPanels.containsKey(user.getUniqueId())) {
if (openPanels.containsKey(user.getUniqueId()) &&
openPanels.get(user.getUniqueId()).getInventory().equals(event.getClickedInventory())) {
// Cancel the event. If they don't want it to be cancelled then the click handler(s) should
// uncancel it. If gui was from our environment, then cancel event anyway.
event.setCancelled(true);
Expand Down

0 comments on commit ebe2f5a

Please sign in to comment.