mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-02 23:53:28 +01:00
Fixed clicking outside of inventory closing it
I edited it so it only happens on BentoBox's panels. Having it closing "every" inventory was causing issues with vanilla inventories (crafting table, etc...) I could not fix the related tests though : PanelListenerManagerTest#testOnInventoryClickOutside (PanelListenerManagerTest.java:128) is failing every time.
This commit is contained in:
parent
cc6aaa1fd1
commit
918f6de782
@ -24,18 +24,19 @@ public class PanelListenerManager implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
|
||||||
|
Inventory inventory = event.getInventory(); // The inventory that was clicked on
|
||||||
|
// Open the inventory panel that this player has open (they can only ever have one)
|
||||||
|
if (openPanels.containsKey(user.getUniqueId())) {
|
||||||
|
// Check the name of the panel
|
||||||
|
if (inventory.getName().equals(openPanels.get(user.getUniqueId()).getInventory().getName())) {
|
||||||
// Close inventory if clicked outside and if setting is true
|
// Close inventory if clicked outside and if setting is true
|
||||||
if (BentoBox.getInstance().getSettings().isClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
|
if (BentoBox.getInstance().getSettings().isClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
|
||||||
event.getWhoClicked().closeInventory();
|
event.getWhoClicked().closeInventory();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
|
|
||||||
Inventory inventory = event.getInventory(); // The inventory that was
|
// Cancel the event. If they don't want it to be cancelled then the click handler(s) should uncancel it
|
||||||
// Open the inventory panel that this player has open (they can only ever have one)
|
|
||||||
if (openPanels.containsKey(user.getUniqueId())) {
|
|
||||||
// Check the name of the panel
|
|
||||||
if (inventory.getName().equals(openPanels.get(user.getUniqueId()).getInventory().getName())) {
|
|
||||||
// Cancel the event. If they don't want it to be canceled then the click handler(s) should uncancel it
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
// Get the panel itself
|
// Get the panel itself
|
||||||
Panel panel = openPanels.get(user.getUniqueId());
|
Panel panel = openPanels.get(user.getUniqueId());
|
||||||
@ -67,10 +68,8 @@ public class PanelListenerManager implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onLogOut(PlayerQuitEvent event) {
|
public void onLogOut(PlayerQuitEvent event) {
|
||||||
if (openPanels.containsKey(event.getPlayer().getUniqueId())) {
|
|
||||||
openPanels.remove(event.getPlayer().getUniqueId());
|
openPanels.remove(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the openPanels
|
* @return the openPanels
|
||||||
|
@ -114,7 +114,6 @@ public class PanelListenerManagerTest {
|
|||||||
|
|
||||||
// Clear the static panels
|
// Clear the static panels
|
||||||
PanelListenerManager.getOpenPanels().clear();
|
PanelListenerManager.getOpenPanels().clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user