Search in sources :

Example 1 with InteractItemRunnable

use of org.anhcraft.spaciouslib.inventory.InteractItemRunnable in project SpaciousLib by anhcraft.

the class InteractItemListener method interact.

@EventHandler(priority = EventPriority.MONITOR)
public void interact(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    Inventory inventory = CompatibilityInventoryClickEvent.getInventory(event);
    ClickType type = event.getClick();
    if (inventory != null && data.containsKey(inventory)) {
        event.setCancelled(true);
        event.setResult(Event.Result.DENY);
        ItemStack item = event.getCurrentItem();
        if (item != null && !item.getType().equals(Material.AIR) && data.get(inventory).containsKey(item)) {
            LinkedHashMap<ItemStack, InteractItemRunnable> items = data.get(inventory);
            items.get(item).run(player, item, type, event.getSlot());
            data.put(inventory, items);
        }
    }
}
Also used : InteractItemRunnable(org.anhcraft.spaciouslib.inventory.InteractItemRunnable) Player(org.bukkit.entity.Player) ClickType(org.bukkit.event.inventory.ClickType) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

InteractItemRunnable (org.anhcraft.spaciouslib.inventory.InteractItemRunnable)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ClickType (org.bukkit.event.inventory.ClickType)1 Inventory (org.bukkit.inventory.Inventory)1 ItemStack (org.bukkit.inventory.ItemStack)1