Java Code Examples for org.bukkit.event.inventory.InventoryAction#PICKUP_ALL

The following examples show how to use org.bukkit.event.inventory.InventoryAction#PICKUP_ALL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CrateControl.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onAdminMenuClick(InventoryClickEvent e) {
    Inventory inv = e.getInventory();
    Player player = (Player) e.getWhoClicked();
    if (inv != null && e.getView().getTitle().equals(Methods.sanitizeColor("&4&lAdmin Keys"))) {
        e.setCancelled(true);
        if (!Methods.permCheck(player, "admin")) {
            player.closeInventory();
            return;
        }
        //Added the >= due to an error about a raw slot set at -999.
        if (e.getRawSlot() < inv.getSize() && e.getRawSlot() >= 0) {//Clicked in the admin menu.
            ItemStack item = inv.getItem(e.getRawSlot());
            if (cc.isKey(item)) {
                Crate crate = cc.getCrateFromKey(item);
                if (e.getAction() == InventoryAction.PICKUP_ALL) {
                    player.getInventory().addItem(crate.getKey());
                } else if (e.getAction() == InventoryAction.PICKUP_HALF) {
                    cc.addKeys(1, player, crate, KeyType.VIRTUAL_KEY);
                    String name = null;
                    ItemStack key = crate.getKey();
                    if (key.hasItemMeta() && key.getItemMeta().hasDisplayName()) {
                        name = key.getItemMeta().getDisplayName();
                    }
                    player.sendMessage(Methods.getPrefix() + Methods.color("&a&l+1 " + (name != null ? name : crate.getName())));
                }
            }
        }
    }
}
 
Example 2
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private CraftItemEvent mockCraftingEvent(ItemStack item) {
    Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD));
    Player player = server.addPlayer();

    CraftingInventory inv = Mockito.mock(CraftingInventory.class);
    Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null });

    InventoryView view = player.openInventory(inv);
    CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL);

    listener.onCraft(event);
    return event;
}
 
Example 3
Source File: StoreListener.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
/**
 * See if a store/unstore event is possible through items being moved into an inventory. Then
 * Storing the value in a array list while the inventory is open.
 *
 * @param evt The InventoryClickEvent used to check item movement
 */
@EventHandler
public void onStoringFilter(InventoryClickEvent evt) {
    if (evt.getAction() == InventoryAction.SWAP_WITH_CURSOR
            || evt.getAction() == InventoryAction.COLLECT_TO_CURSOR
            || evt.getAction() == InventoryAction.PICKUP_SOME
            || evt.getAction() == InventoryAction.PICKUP_HALF
            || evt.getAction() == InventoryAction.PICKUP_ALL
            || evt.getAction() == InventoryAction.PICKUP_ONE) {
        if (evt.getClickedInventory().getType() != null
                && evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
                && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
                || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
                || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)
                && evt.getClickedInventory().getType() == InventoryType.PLAYER
                && (!(storePossible.contains(evt.getWhoClicked())))) {
            storePossible.add((Player) evt.getWhoClicked());
            if (unstorePossible.contains(evt.getWhoClicked())) {
                unstorePossible.remove(evt.getWhoClicked());
            }
        }
        if (evt.getClickedInventory().getType() != null
                && evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
                && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
                || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
                || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)
                && (evt.getClickedInventory().getType() == InventoryType.CHEST
                || evt.getClickedInventory().getType() == InventoryType.ENDER_CHEST
                || evt.getClickedInventory().getType() == InventoryType.HOPPER
                || evt.getClickedInventory().getType() == InventoryType.DISPENSER
                || evt.getClickedInventory().getType() == InventoryType.DROPPER)
                && (!(unstorePossible.contains(evt.getWhoClicked())))) {
            unstorePossible.add((Player) evt.getWhoClicked());
            if (storePossible.contains(evt.getWhoClicked())) {
                storePossible.remove(evt.getWhoClicked());
            }
        }
    }
}