mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 19:55:17 +01:00
Merge pull request #270 from BentoBoxWorld/fix-outside-closing-inventory
Fixed clicking outside of inventory closing even vanilla inventories
This commit is contained in:
commit
13bc945b40
@ -24,18 +24,19 @@ public class PanelListenerManager implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
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
|
||||
if (BentoBox.getInstance().getSettings().isClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
|
||||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
|
||||
Inventory inventory = event.getInventory(); // The inventory that was
|
||||
// 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
|
||||
|
||||
// Cancel the event. If they don't want it to be cancelled then the click handler(s) should uncancel it
|
||||
event.setCancelled(true);
|
||||
// Get the panel itself
|
||||
Panel panel = openPanels.get(user.getUniqueId());
|
||||
@ -67,10 +68,8 @@ public class PanelListenerManager implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onLogOut(PlayerQuitEvent event) {
|
||||
if (openPanels.containsKey(event.getPlayer().getUniqueId())) {
|
||||
openPanels.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the openPanels
|
||||
|
@ -114,14 +114,26 @@ public class PanelListenerManagerTest {
|
||||
|
||||
// Clear the static panels
|
||||
PanelListenerManager.getOpenPanels().clear();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.PanelListenerManager#onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnInventoryClickOutside() {
|
||||
public void testOnInventoryClickOutsideUnknownPanel() {
|
||||
SlotType type = SlotType.OUTSIDE;
|
||||
InventoryClickEvent e = new InventoryClickEvent(view, type, 0, click, inv);
|
||||
plm.onInventoryClick(e);
|
||||
Mockito.verify(player, Mockito.never()).closeInventory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.PanelListenerManager#onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnInventoryClickOutsideKnownPanel() {
|
||||
// Put a panel in the list
|
||||
PanelListenerManager.getOpenPanels().put(uuid, panel);
|
||||
SlotType type = SlotType.OUTSIDE;
|
||||
InventoryClickEvent e = new InventoryClickEvent(view, type, 0, click, inv);
|
||||
plm.onInventoryClick(e);
|
||||
|
Loading…
Reference in New Issue
Block a user