Search in sources :

Example 16 with InventoryType

use of org.bukkit.event.inventory.InventoryType in project Essentials by drtshock.

the class EssentialsPlayerListener method onInventoryCloseEvent.

@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
    Player refreshPlayer = null;
    final Inventory top = event.getView().getTopInventory();
    final InventoryType type = top.getType();
    if (type == InventoryType.PLAYER) {
        final User user = ess.getUser((Player) event.getPlayer());
        user.setInvSee(false);
        refreshPlayer = user.getBase();
    } else if (type == InventoryType.ENDER_CHEST) {
        final User user = ess.getUser((Player) event.getPlayer());
        user.setEnderSee(false);
        refreshPlayer = user.getBase();
    } else if (type == InventoryType.WORKBENCH) {
        final User user = ess.getUser((Player) event.getPlayer());
        if (user.isRecipeSee()) {
            user.setRecipeSee(false);
            event.getView().getTopInventory().clear();
            refreshPlayer = user.getBase();
        }
    } else if (type == InventoryType.CHEST && top.getSize() == 9) {
        final InventoryHolder invHolder = top.getHolder();
        if (invHolder != null && invHolder instanceof HumanEntity) {
            final User user = ess.getUser((Player) event.getPlayer());
            user.setInvSee(false);
            refreshPlayer = user.getBase();
        }
    }
    if (refreshPlayer != null) {
        final Player player = refreshPlayer;
        ess.scheduleSyncDelayedTask(new Runnable() {

            @Override
            public void run() {
                player.updateInventory();
            }
        }, 1);
    }
}
Also used : Player(org.bukkit.entity.Player) InventoryType(org.bukkit.event.inventory.InventoryType) HumanEntity(org.bukkit.entity.HumanEntity) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

InventoryType (org.bukkit.event.inventory.InventoryType)16 Player (org.bukkit.entity.Player)10 ItemStack (org.bukkit.inventory.ItemStack)10 EventHandler (org.bukkit.event.EventHandler)8 Inventory (org.bukkit.inventory.Inventory)7 HumanEntity (org.bukkit.entity.HumanEntity)6 SlotType (org.bukkit.event.inventory.InventoryType.SlotType)4 InventoryHolder (org.bukkit.inventory.InventoryHolder)4 PlayerInventory (org.bukkit.inventory.PlayerInventory)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)3 Wand (com.elmakers.mine.bukkit.wand.Wand)3 InventoryScriptContainer (com.denizenscript.denizen.scripts.containers.core.InventoryScriptContainer)2 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 InventoryAction (org.bukkit.event.inventory.InventoryAction)2 CraftingInventory (org.bukkit.inventory.CraftingInventory)2 BookMeta (org.bukkit.inventory.meta.BookMeta)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 ImprovedOfflinePlayer (com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer)1 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)1