mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-13 10:51:20 +01:00
parent
a4bef159be
commit
2bc82dd3cf
@ -22,6 +22,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.EnchantingInventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
@ -69,6 +70,14 @@ public class InventoryListener extends FlagListener
|
||||
public void onInventoryClick(InventoryClickEvent e)
|
||||
{
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
|
||||
// Enchanting
|
||||
if (e.getInventory() instanceof EnchantingInventory) {
|
||||
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.ENCHANTING);
|
||||
return;
|
||||
}
|
||||
|
||||
// Inventory holders
|
||||
InventoryHolder inventoryHolder = e.getInventory().getHolder();
|
||||
|
||||
if (inventoryHolder == null || !(e.getWhoClicked() instanceof Player))
|
||||
@ -130,7 +139,6 @@ public class InventoryListener extends FlagListener
|
||||
}
|
||||
else if (inventoryHolder instanceof ChestBoat)
|
||||
{
|
||||
// TODO: 1.19 added chest boat. Remove compatibility check when 1.18 is dropped.
|
||||
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.CHEST);
|
||||
}
|
||||
else if (!(inventoryHolder instanceof Player))
|
||||
|
@ -32,6 +32,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.inventory.EnchantingInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
@ -82,6 +83,25 @@ public class InventoryListenerTest extends AbstractCommonSetup {
|
||||
l = new InventoryListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.InventoryListener#onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnInventoryClickEnchantingAllowed() {
|
||||
InventoryView view = mock(InventoryView.class);
|
||||
when(view.getPlayer()).thenReturn(player);
|
||||
EnchantingInventory inv = mock(EnchantingInventory.class);
|
||||
when(inv.getSize()).thenReturn(9);
|
||||
when(view.getTopInventory()).thenReturn(inv);
|
||||
when(inv.getLocation()).thenReturn(location);
|
||||
when(view.getBottomInventory()).thenReturn(inv);
|
||||
SlotType slotType = SlotType.CRAFTING;
|
||||
InventoryAction action = InventoryAction.PLACE_ONE;
|
||||
InventoryClickEvent e = new InventoryClickEvent(view, slotType, 0, ClickType.LEFT, action );
|
||||
l.onInventoryClick(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.InventoryListener#onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent)}.
|
||||
*/
|
||||
@ -195,6 +215,27 @@ public class InventoryListenerTest extends AbstractCommonSetup {
|
||||
verify(notifier, times(HOLDERS.size())).notify(any(), eq("protection.protected"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.InventoryListener#onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnInventoryClickEnchantingNotAllowed() {
|
||||
when(island.isAllowed(any(), any())).thenReturn(false);
|
||||
InventoryView view = mock(InventoryView.class);
|
||||
when(view.getPlayer()).thenReturn(player);
|
||||
EnchantingInventory inv = mock(EnchantingInventory.class);
|
||||
when(inv.getSize()).thenReturn(9);
|
||||
when(view.getTopInventory()).thenReturn(inv);
|
||||
when(inv.getLocation()).thenReturn(location);
|
||||
when(view.getBottomInventory()).thenReturn(inv);
|
||||
SlotType slotType = SlotType.CRAFTING;
|
||||
InventoryAction action = InventoryAction.PLACE_ONE;
|
||||
InventoryClickEvent e = new InventoryClickEvent(view, slotType, 0, ClickType.LEFT, action );
|
||||
l.onInventoryClick(e);
|
||||
assertTrue(e.isCancelled());
|
||||
verify(notifier).notify(any(), eq("protection.protected"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.InventoryListener#onInventoryClick(org.bukkit.event.inventory.InventoryClickEvent)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user