Search in sources :

Example 1 with InteractType

use of com.playmonumenta.scriptedquests.quests.InteractableEntry.InteractType in project scripted-quests by TeamMonumenta.

the class InteractablesListener method inventoryClickEvent.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void inventoryClickEvent(InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    ItemStack item = event.getCurrentItem();
    ClickType type = event.getClick();
    InteractType interactType = null;
    switch(type) {
        case RIGHT:
            interactType = InteractType.RIGHT_CLICK_INVENTORY;
            break;
        case LEFT:
            interactType = InteractType.LEFT_CLICK_INVENTORY;
            break;
        default:
            break;
    }
    if (item == null || item.getType() == Material.AIR || interactType == null) {
        // No point continuing
        return;
    }
    if (item != null && !item.getType().isAir() && player.getCooldown(item.getType()) > 0) {
        /* Player's item is on cooldown, don't use it to interact to trigger interactions */
        return;
    }
    if (mPlugin.mInteractableManager.clickInventoryEvent(mPlugin, player, item, interactType)) {
        event.setCancelled(true);
    }
}
Also used : InteractType(com.playmonumenta.scriptedquests.quests.InteractableEntry.InteractType) Player(org.bukkit.entity.Player) ClickType(org.bukkit.event.inventory.ClickType) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

InteractType (com.playmonumenta.scriptedquests.quests.InteractableEntry.InteractType)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ClickType (org.bukkit.event.inventory.ClickType)1 ItemStack (org.bukkit.inventory.ItemStack)1