Search in sources :

Example 1 with InventoryAction

use of org.bukkit.event.inventory.InventoryAction in project MagicPlugin by elBukkit.

the class SkillSelectorAction method clicked.

@Override
public void clicked(InventoryClickEvent event) {
    InventoryAction action = event.getAction();
    if (action == InventoryAction.NOTHING) {
        int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
        page = page + direction;
        openInventory();
        event.setCancelled(true);
        return;
    }
    ItemStack clickedItem = event.getCurrentItem();
    if (clickedItem != null && InventoryUtils.getMetaBoolean(clickedItem, "unavailable", false)) {
        event.setCancelled(true);
        return;
    }
    Mage mage = context.getMage();
    MageController controller = mage.getController();
    Inventory inventory = mage.getInventory();
    boolean isContainerSlot = event.getSlot() == event.getRawSlot();
    boolean isDrop = action == InventoryAction.DROP_ALL_CURSOR || action == InventoryAction.DROP_ALL_SLOT || action == InventoryAction.DROP_ONE_CURSOR || action == InventoryAction.DROP_ONE_SLOT;
    if (!isContainerSlot && isDrop && controller.isSkill(clickedItem) && !InventoryUtils.getMetaBoolean(clickedItem, "undroppable", false)) {
        inventory.setItem(event.getSlot(), null);
        return;
    }
    if (inventoryLimit > 0) {
        boolean isHotbar = event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD;
        if (isHotbar) {
            ItemStack destinationItem = inventory.getItem(event.getHotbarButton());
            if (controller.isSkill(destinationItem))
                return;
            isHotbar = controller.isSkill(clickedItem);
        }
        if (!isContainerSlot && !isHotbar)
            return;
        int skillCount = 0;
        for (int i = 0; i < inventory.getSize(); i++) {
            ItemStack item = inventory.getItem(i);
            if (controller.isSkill(item))
                skillCount++;
        }
        if (skillCount >= inventoryLimit) {
            event.setCancelled(true);
        }
        return;
    }
    // We don't allow quick-casting here if there is an inventory limit.
    if (action == InventoryAction.PICKUP_HALF) {
        Spell spell = mage.getSpell(Wand.getSpell(clickedItem));
        if (spell != null) {
            spell.cast();
        }
        mage.getPlayer().closeInventory();
        event.setCancelled(true);
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) Spell(com.elmakers.mine.bukkit.api.spell.Spell) InventoryAction(org.bukkit.event.inventory.InventoryAction)

Example 2 with InventoryAction

use of org.bukkit.event.inventory.InventoryAction in project MagicPlugin by elBukkit.

the class BrushSelectAction method clicked.

@Override
public void clicked(InventoryClickEvent event) {
    event.setCancelled(true);
    InventoryAction action = event.getAction();
    if (context != null) {
        Mage mage = context.getMage();
        if (action == InventoryAction.NOTHING) {
            int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
            page = page + direction;
            mage.deactivateGUI();
            perform(context);
            event.setCancelled(true);
            return;
        }
        ItemStack item = event.getCurrentItem();
        String set = InventoryUtils.getMetaString(item, "brush_set", null);
        if (set != null) {
            if (set.equals("schematics")) {
                String inventoryTitle = context.getMessage("schematics_title", "Schematics");
                int invSize = ((schematics.size() + 9) / 9) * 9;
                Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
                for (ItemStack schematicItem : schematics) {
                    displayInventory.addItem(schematicItem);
                }
                mage.deactivateGUI();
                mage.activateGUI(this, displayInventory);
                return;
            } else if (set.equals("variants")) {
                MaterialAndData baseMaterial = new MaterialAndData(item);
                String baseName = baseMaterial.getBaseName();
                String inventoryTitle = context.getMessage("variants_title", "$variant Types").replace("$variant", baseName);
                String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
                MaterialAndData brushMaterial = new MaterialAndData(brushKey);
                List<ItemStack> variantList = variants.get(brushMaterial.getMaterial());
                int invSize = ((variantList.size() + 9) / 9) * 9;
                Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
                for (ItemStack variantItem : variantList) {
                    displayInventory.addItem(variantItem);
                }
                mage.deactivateGUI();
                mage.activateGUI(this, displayInventory);
                return;
            }
        }
        mage.deactivateGUI();
        Wand wand = context.getWand();
        if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isBrush(item)) {
            String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
            wand.setActiveBrush(brushKey);
        }
    }
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) InventoryAction(org.bukkit.event.inventory.InventoryAction)

Example 3 with InventoryAction

use of org.bukkit.event.inventory.InventoryAction in project MagicPlugin by elBukkit.

the class InventoryController method onInventoryClick.

@SuppressWarnings("deprecation")
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled())
        return;
    if (!(event.getWhoClicked() instanceof Player))
        return;
    Player player = (Player) event.getWhoClicked();
    final Mage mage = controller.getMage(player);
    GUIAction gui = mage.getActiveGUI();
    if (gui != null) {
        gui.clicked(event);
        return;
    }
    // Check for temporary items and skill items
    InventoryAction action = event.getAction();
    InventoryType inventoryType = event.getInventory().getType();
    boolean isPlayerInventory = inventoryType == InventoryType.CRAFTING || inventoryType == InventoryType.PLAYER;
    ItemStack clickedItem = event.getCurrentItem();
    boolean isDrop = event.getClick() == ClickType.DROP || event.getClick() == ClickType.CONTROL_DROP;
    boolean isSkill = clickedItem != null && Wand.isSkill(clickedItem);
    // Check for right-click-to-use
    boolean isRightClick = action == InventoryAction.PICKUP_HALF;
    if (isSkill && isRightClick) {
        mage.useSkill(clickedItem);
        player.closeInventory();
        event.setCancelled(true);
        return;
    }
    if (clickedItem != null && NMSUtils.isTemporary(clickedItem)) {
        String message = NMSUtils.getTemporaryMessage(clickedItem);
        if (message != null && message.length() > 1) {
            mage.sendMessage(message);
        }
        ItemStack replacement = NMSUtils.getReplacement(clickedItem);
        event.setCurrentItem(replacement);
        event.setCancelled(true);
        return;
    }
    // Check for wearing spells
    ItemStack heldItem = event.getCursor();
    boolean heldSpell = Wand.isSpell(heldItem);
    if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
        if (heldSpell) {
            event.setCancelled(true);
            return;
        }
        if (Wand.isWand(clickedItem) || Wand.isWand(heldItem)) {
            controller.onArmorUpdated(mage);
        }
    }
    boolean isHotbar = event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD;
    if (isHotbar && event.getSlotType() == InventoryType.SlotType.ARMOR) {
        int slot = event.getHotbarButton();
        ItemStack item = mage.getPlayer().getInventory().getItem(slot);
        if (item != null && Wand.isSpell(item)) {
            event.setCancelled(true);
            return;
        }
        controller.onArmorUpdated(mage);
    }
    Wand activeWand = mage.getActiveWand();
    boolean isWandInventoryOpen = activeWand != null && activeWand.isInventoryOpen();
    // Preventing putting skills in containers
    if (isSkill && !isPlayerInventory && !isWandInventoryOpen) {
        if (!isDrop) {
            event.setCancelled(true);
        }
        return;
    }
    boolean isFurnace = inventoryType == InventoryType.FURNACE;
    boolean isChest = inventoryType == InventoryType.CHEST || inventoryType == InventoryType.HOPPER || inventoryType == InventoryType.DISPENSER || inventoryType == InventoryType.DROPPER;
    // TODO: use enum when dropping backwards compat
    if (!isChest)
        isChest = inventoryType.name().equals("SHULKER_BOX");
    boolean clickedWand = Wand.isWand(clickedItem);
    boolean isContainerSlot = event.getSlot() == event.getRawSlot();
    if (isWandInventoryOpen) {
        // Don't allow the offhand slot to be messed with while the spell inventory is open
        if (event.getRawSlot() == 45) {
            event.setCancelled(true);
            return;
        }
        // Don't allow putting spells in a crafting slot
        if (event.getSlotType() == InventoryType.SlotType.CRAFTING && heldSpell) {
            event.setCancelled(true);
            return;
        }
        if (Wand.isSpell(clickedItem) && clickedItem.getAmount() != 1) {
            clickedItem.setAmount(1);
        }
        if (clickedWand) {
            event.setCancelled(true);
            if (dropChangesPages || isRightClick) {
                activeWand.cycleInventory();
            } else {
                activeWand.cycleHotbar(1);
                // There doesn't seem to be any other way to allow cycling in creative
                if (inventoryType == InventoryType.PLAYER) {
                    activeWand.cycleInventory();
                }
            }
            return;
        }
        // So many ways to try and move the wand around, that we have to watch for!
        if (isHotbar && Wand.isWand(player.getInventory().getItem(event.getHotbarButton()))) {
            event.setCancelled(true);
            return;
        }
        // Can't wear spells
        if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) {
            if (controller.isWearable(clickedItem)) {
                event.setCancelled(true);
                return;
            }
        }
        // but perhaps happens with lag?
        if (Wand.isWand(event.getCursor())) {
            activeWand.closeInventory();
            event.setCursor(null);
            event.setCancelled(true);
            return;
        }
    } else if (activeWand != null) {
        // Check for changes that could have been made to the active wand
        int activeSlot = player.getInventory().getHeldItemSlot();
        if (event.getSlot() == activeSlot || (isHotbar && event.getHotbarButton() == activeSlot)) {
            mage.checkWand();
            activeWand = mage.getActiveWand();
        }
    }
    // Don't allow smelting wands
    if (isFurnace && clickedWand) {
        event.setCancelled(true);
        return;
    }
    if (isFurnace && isHotbar) {
        ItemStack destinationItem = player.getInventory().getItem(event.getHotbarButton());
        if (Wand.isWand(destinationItem)) {
            event.setCancelled(true);
            return;
        }
    }
    if (InventoryUtils.getMetaBoolean(clickedItem, "unmoveable", false)) {
        event.setCancelled(true);
        return;
    }
    if (isHotbar) {
        ItemStack destinationItem = player.getInventory().getItem(event.getHotbarButton());
        if (InventoryUtils.getMetaBoolean(destinationItem, "unmoveable", false)) {
            event.setCancelled(true);
            return;
        }
        if (isChest && InventoryUtils.getMetaBoolean(destinationItem, "unstashable", false) && !player.hasPermission("Magic.wand.override_stash")) {
            event.setCancelled(true);
            return;
        }
    }
    // Check for unstashable wands
    if (isChest && !isContainerSlot && !player.hasPermission("Magic.wand.override_stash")) {
        if (InventoryUtils.getMetaBoolean(clickedItem, "unstashable", false)) {
            event.setCancelled(true);
            return;
        }
    }
    // Check for taking bound wands out of chests
    if (isChest && isContainerSlot && Wand.isBound(clickedItem)) {
        Wand testWand = controller.getWand(clickedItem);
        if (!testWand.canUse(player)) {
            event.setCancelled(true);
            return;
        }
    }
    // Check for armor changing
    if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) {
        if (controller.isWearable(clickedItem)) {
            controller.onArmorUpdated(mage);
        }
    }
    // or dropping undroppable wands
    if (isDrop) {
        if (InventoryUtils.getMetaBoolean(clickedItem, "undroppable", false)) {
            event.setCancelled(true);
            if (activeWand != null) {
                if (activeWand.getHotbarCount() > 1) {
                    activeWand.cycleHotbar(1);
                } else {
                    activeWand.closeInventory();
                }
            }
            return;
        }
        if (activeWand != null && activeWand.isInventoryOpen()) {
            ItemStack droppedItem = clickedItem;
            if (!Wand.isSpell(droppedItem)) {
                mage.giveItem(droppedItem);
                event.setCurrentItem(null);
                event.setCancelled(true);
                return;
            }
            // This is a hack to deal with spells on cooldown disappearing,
            // Since the event handler doesn't match the zero-count itemstacks
            Integer slot = event.getSlot();
            int heldSlot = player.getInventory().getHeldItemSlot();
            Inventory hotbar = activeWand.getHotbar();
            if (hotbar != null && slot >= 0 && slot <= hotbar.getSize() && slot != heldSlot && activeWand.getMode() == WandMode.INVENTORY) {
                if (slot > heldSlot)
                    slot--;
                if (slot < hotbar.getSize()) {
                    droppedItem = hotbar.getItem(slot);
                } else {
                    slot = null;
                }
            } else {
                slot = null;
            }
            if (!controller.isSpellDroppingEnabled()) {
                player.closeInventory();
                String spellName = Wand.getSpell(droppedItem);
                if (spellName != null && !activeWand.isManualQuickCastDisabled() && enableInventoryCasting) {
                    Spell spell = mage.getSpell(spellName);
                    if (spell != null) {
                        activeWand.cast(spell);
                        // Just in case a spell has levelled up... jeez!
                        if (hotbar != null && slot != null) {
                            droppedItem = hotbar.getItem(slot);
                        }
                    }
                }
                event.setCancelled(true);
                // This is needed to avoid spells on cooldown disappearing from the hotbar
                if (hotbar != null && slot != null && mage.getActiveGUI() == null) {
                    player.getInventory().setItem(event.getSlot(), droppedItem);
                    DeprecatedUtils.updateInventory(player);
                }
                return;
            }
            ItemStack newDrop = controller.removeItemFromWand(activeWand, droppedItem);
            if (newDrop != null) {
                Location location = player.getLocation();
                Item item = location.getWorld().dropItem(location, newDrop);
                SafetyUtils.setVelocity(item, location.getDirection().normalize());
            } else {
                event.setCancelled(true);
            }
        }
        return;
    }
    // Check for wand cycling with active inventory
    if (activeWand != null) {
        WandMode wandMode = activeWand.getMode();
        boolean isChestInventory = wandMode == WandMode.CHEST || wandMode == WandMode.SKILLS;
        if ((wandMode == WandMode.INVENTORY && isPlayerInventory) || (isChestInventory && inventoryType == InventoryType.CHEST)) {
            if (activeWand.isInventoryOpen()) {
                if (event.getAction() == InventoryAction.NOTHING) {
                    int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
                    activeWand.cycleInventory(direction);
                    event.setCancelled(true);
                    return;
                }
                if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
                    event.setCancelled(true);
                    return;
                }
                // Chest mode falls back to selection from here.
                boolean isInventoryQuickSelect = isRightClick && wandMode == WandMode.INVENTORY && enableInventorySelection;
                if (isInventoryQuickSelect || wandMode == WandMode.CHEST) {
                    player.closeInventory();
                    mage.activateIcon(activeWand, clickedItem);
                    event.setCancelled(true);
                }
                // Prevent clicking any non-skill item when a skill inventory is open
                if (wandMode == WandMode.SKILLS && clickedItem != null && clickedItem.getType() != Material.AIR && !Wand.isSkill(clickedItem)) {
                    event.setCancelled(true);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) InventoryType(org.bukkit.event.inventory.InventoryType) GUIAction(com.elmakers.mine.bukkit.api.action.GUIAction) Wand(com.elmakers.mine.bukkit.wand.Wand) Spell(com.elmakers.mine.bukkit.api.spell.Spell) InventoryAction(org.bukkit.event.inventory.InventoryAction) Item(org.bukkit.entity.Item) Mage(com.elmakers.mine.bukkit.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack) CraftingInventory(org.bukkit.inventory.CraftingInventory) Inventory(org.bukkit.inventory.Inventory) WandMode(com.elmakers.mine.bukkit.wand.WandMode) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 4 with InventoryAction

use of org.bukkit.event.inventory.InventoryAction in project MagicPlugin by elBukkit.

the class AnvilController method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled())
        return;
    if (!(event.getWhoClicked() instanceof Player))
        return;
    InventoryType inventoryType = event.getInventory().getType();
    SlotType slotType = event.getSlotType();
    Player player = (Player) event.getWhoClicked();
    Mage mage = controller.getMage(player);
    if (inventoryType == InventoryType.ANVIL) {
        ItemStack cursor = event.getCursor();
        ItemStack current = event.getCurrentItem();
        Inventory anvilInventory = event.getInventory();
        InventoryAction action = event.getAction();
        ItemStack firstItem = anvilInventory.getItem(0);
        ItemStack secondItem = anvilInventory.getItem(1);
        // Handle direct movement
        if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
            if (!Wand.isWand(current))
                return;
            // Moving from anvil back to inventory
            if (slotType == SlotType.CRAFTING) {
                Wand wand = controller.getWand(current);
                wand.updateName(true);
            } else if (slotType == SlotType.RESULT) {
                // Don't allow combining
                if (!combiningEnabled) {
                    if (firstItem != null && secondItem != null) {
                        event.setCancelled(true);
                        return;
                    }
                }
                // Taking from result slot
                ItemMeta meta = current.getItemMeta();
                String newName = meta.getDisplayName();
                Wand wand = controller.getWand(current);
                if (!wand.canUse(player)) {
                    event.setCancelled(true);
                    mage.sendMessage(controller.getMessages().get("wand.bound").replace("$name", wand.getOwner()));
                    return;
                }
                wand.setName(newName);
                if (organizingEnabled) {
                    wand.organizeInventory(controller.getMage(player));
                }
                wand.tryToOwn(player);
            } else {
                // Moving from inventory to anvil
                Wand wand = controller.getWand(current);
                wand.updateName(false);
            }
            return;
        }
        // Set/unset active names when starting to craft
        if (slotType == SlotType.CRAFTING) {
            // Putting a wand into the anvil's crafting slot
            if (Wand.isWand(cursor)) {
                Wand wand = controller.getWand(cursor);
                wand.updateName(false);
            }
            // Taking a wand out of the anvil's crafting slot
            if (Wand.isWand(current)) {
                Wand wand = controller.getWand(current);
                if (clearDescriptionOnRename) {
                    wand.setDescription("");
                }
                wand.updateName(true);
                if (event.getWhoClicked() instanceof Player) {
                    wand.tryToOwn((Player) event.getWhoClicked());
                }
            }
            return;
        }
        // Rename wand when taking from result slot
        if (slotType == SlotType.RESULT && Wand.isWand(current)) {
            if (!combiningEnabled) {
                if (firstItem != null && secondItem != null) {
                    event.setCancelled(true);
                    return;
                }
            }
            ItemMeta meta = current.getItemMeta();
            String newName = meta.getDisplayName();
            Wand wand = controller.getWand(current);
            if (!wand.canUse(player)) {
                event.setCancelled(true);
                mage.sendMessage(controller.getMessages().get("wand.bound").replace("$name", wand.getOwner()));
                return;
            }
            wand.setName(newName);
            if (organizingEnabled) {
                wand.organizeInventory(controller.getMage(player));
            }
            wand.tryToOwn(player);
            return;
        }
        if (combiningEnabled && slotType == SlotType.RESULT) {
            // I guess I need to wait for the long-awaited anvil API?
            if (Wand.isWand(firstItem) && Wand.isWand(secondItem)) {
                Wand firstWand = controller.getWand(firstItem);
                Wand secondWand = controller.getWand(secondItem);
                if (!firstWand.isModifiable() || !secondWand.isModifiable()) {
                    mage.sendMessage("One of your wands can not be combined");
                    return;
                }
                if (!firstWand.canUse(player) || !secondWand.canUse(player)) {
                    mage.sendMessage("One of those wands is not bound to you");
                    return;
                }
                if (!firstWand.add(secondWand)) {
                    mage.sendMessage("These wands can not be combined with each other");
                    return;
                }
                anvilInventory.setItem(0, null);
                anvilInventory.setItem(1, null);
                cursor.setType(Material.AIR);
                if (organizingEnabled) {
                    firstWand.organizeInventory(mage);
                }
                firstWand.tryToOwn(player);
                player.getInventory().addItem(firstWand.getItem());
                mage.sendMessage("Your wands have been combined!");
            // This seems to work in the debugger, but.. doesn't do anything.
            // InventoryUtils.setInventoryResults(anvilInventory, newWand.getItem());
            } else if (organizingEnabled && Wand.isWand(firstItem)) {
                Wand firstWand = controller.getWand(firstItem);
                // TODO: Can't get the anvil's text from here.
                anvilInventory.setItem(0, null);
                anvilInventory.setItem(1, null);
                cursor.setType(Material.AIR);
                firstWand.organizeInventory(mage);
                firstWand.tryToOwn(player);
                player.getInventory().addItem(firstWand.getItem());
                mage.sendMessage("Your wand has been organized!");
            }
            return;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) InventoryType(org.bukkit.event.inventory.InventoryType) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta) SlotType(org.bukkit.event.inventory.InventoryType.SlotType) InventoryAction(org.bukkit.event.inventory.InventoryAction) EventHandler(org.bukkit.event.EventHandler)

Example 5 with InventoryAction

use of org.bukkit.event.inventory.InventoryAction in project MassiveCore by MassiveCraft.

the class InventoryUtil method getAlter.

private static InventoryAlter getAlter(InventoryClickEvent event) {
    if (isOutside(event))
        return InventoryAlter.NONE;
    boolean topClicked = isTopInventory(event);
    InventoryAction action = event.getAction();
    if (topClicked) {
        switch(action) {
            // What is the best thing to do?
            case UNKNOWN:
                return InventoryAlter.BOTH;
            // Possibly both
            case HOTBAR_SWAP:
                ItemStack hotbar = event.getView().getBottomInventory().getItem(event.getHotbarButton());
                ItemStack current = event.getCurrentItem();
                boolean give = isSomething(hotbar);
                boolean take = isSomething(current);
                return InventoryAlter.get(give, take);
            // Neither give nor take
            case NOTHING:
                return InventoryAlter.NONE;
            case CLONE_STACK:
                return InventoryAlter.NONE;
            case DROP_ALL_CURSOR:
                return InventoryAlter.NONE;
            case DROP_ONE_CURSOR:
                return InventoryAlter.NONE;
            // Take
            case PICKUP_ALL:
                return InventoryAlter.TAKE;
            case PICKUP_HALF:
                return InventoryAlter.TAKE;
            case PICKUP_ONE:
                return InventoryAlter.TAKE;
            case PICKUP_SOME:
                return InventoryAlter.TAKE;
            case MOVE_TO_OTHER_INVENTORY:
                return InventoryAlter.TAKE;
            case COLLECT_TO_CURSOR:
                return InventoryAlter.TAKE;
            case HOTBAR_MOVE_AND_READD:
                return InventoryAlter.TAKE;
            case DROP_ONE_SLOT:
                return InventoryAlter.TAKE;
            case DROP_ALL_SLOT:
                return InventoryAlter.TAKE;
            // Give
            case PLACE_ALL:
                return InventoryAlter.GIVE;
            case PLACE_ONE:
                return InventoryAlter.GIVE;
            case PLACE_SOME:
                return InventoryAlter.GIVE;
            case SWAP_WITH_CURSOR:
                return InventoryAlter.BOTH;
        }
        throw new RuntimeException("Unsupported action: " + action);
    } else {
        // What is the best thing to do?
        if (action == InventoryAction.UNKNOWN)
            return InventoryAlter.BOTH;
        if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY)
            return InventoryAlter.GIVE;
        // We will return TAKE for security reasons.
        if (action == InventoryAction.COLLECT_TO_CURSOR)
            return InventoryAlter.TAKE;
        return InventoryAlter.NONE;
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) InventoryAction(org.bukkit.event.inventory.InventoryAction)

Aggregations

InventoryAction (org.bukkit.event.inventory.InventoryAction)6 ItemStack (org.bukkit.inventory.ItemStack)6 Inventory (org.bukkit.inventory.Inventory)4 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 Wand (com.elmakers.mine.bukkit.wand.Wand)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 InventoryType (org.bukkit.event.inventory.InventoryType)2 GUIAction (com.elmakers.mine.bukkit.api.action.GUIAction)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)1 Mage (com.elmakers.mine.bukkit.magic.Mage)1 WandMode (com.elmakers.mine.bukkit.wand.WandMode)1 MassiveList (com.massivecraft.massivecore.collections.MassiveList)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1