Improved InventoryListener

This commit is contained in:
Florian CUNY 2018-12-28 10:42:38 +01:00
parent d289b51b35
commit a33fc82a4a

View File

@ -13,6 +13,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.InventoryHolder;
import world.bentobox.bentobox.api.flags.FlagListener; import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
@ -20,39 +21,38 @@ import world.bentobox.bentobox.lists.Flags;
/** /**
* Handles inventory protection * Handles inventory protection
* @author tastybento * @author tastybento
*
*/ */
public class InventoryListener extends FlagListener { public class InventoryListener extends FlagListener {
/** /**
* Prevents visitors picking items from inventories * Prevents players picking items from inventories
* @param e - event * @param e - event
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onMountInventoryClick(InventoryClickEvent e) { public void onInventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() == null) { InventoryHolder inventoryHolder = e.getInventory().getHolder();
if (inventoryHolder == null) {
return; return;
} }
if (e.getInventory().getHolder() instanceof Animals) { setUser(User.getInstance(e.getWhoClicked()));
if (inventoryHolder instanceof Animals) {
checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY); checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
} }
else if (e.getInventory().getHolder() instanceof Chest else if (inventoryHolder instanceof Chest
|| e.getInventory().getHolder() instanceof Dispenser || inventoryHolder instanceof Dispenser
|| e.getInventory().getHolder() instanceof Hopper || inventoryHolder instanceof Hopper
|| e.getInventory().getHolder() instanceof Dropper || inventoryHolder instanceof Dropper
|| e.getInventory().getHolder() instanceof ShulkerBox) { || inventoryHolder instanceof ShulkerBox) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.CHEST); checkIsland(e, e.getInventory().getLocation(), Flags.CHEST);
} }
else if (e.getInventory().getHolder() instanceof Furnace) { else if (inventoryHolder instanceof Furnace) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.FURNACE); checkIsland(e, e.getInventory().getLocation(), Flags.FURNACE);
} }
else if (e.getInventory().getHolder() instanceof BrewingStand) { else if (inventoryHolder instanceof BrewingStand) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.BREWING); checkIsland(e, e.getInventory().getLocation(), Flags.BREWING);
} }
else if (e.getInventory().getHolder() instanceof Beacon) { else if (inventoryHolder instanceof Beacon) {
setUser(User.getInstance(e.getWhoClicked())).checkIsland(e, e.getInventory().getLocation(), Flags.BEACON); checkIsland(e, e.getInventory().getLocation(), Flags.BEACON);
} }
} }
} }