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

The following examples show how to use org.bukkit.event.inventory.InventoryAction#COLLECT_TO_CURSOR . 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: ItemTransferListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void collectToCursor(InventoryClickEvent event) {
    // If this hasn't been cancelled yet, cancel it so our implementation can take over
    if(event.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
        event.setCancelled(true);
        this.collectToCursor = true;
    }
}
 
Example 2
Source File: DuctSettingsInventory.java    From Transport-Pipes with MIT License 5 votes vote down vote up
@EventHandler
public void onInvClick(InventoryClickEvent e) {
    if (e.getInventory() != null && e.getInventory().equals(inv) && e.getWhoClicked() instanceof Player) {
        if (itemService.isItemWildcardOrBarrier(e.getCurrentItem())) {
            e.setCancelled(true);
            return;
        }
        //don't call click method when double clicked, because before a double click, left click was already registered twice
        if (e.getClick() != ClickType.DOUBLE_CLICK && click((Player) e.getWhoClicked(), e.getRawSlot(), e.getClick())) {
            e.setCancelled(true);
        } else if (e.getClick() == ClickType.DOUBLE_CLICK && e.getAction() == InventoryAction.COLLECT_TO_CURSOR && collect_to_cursor((Player) e.getWhoClicked(), e.getCursor(), e.getRawSlot())) {
            e.setCancelled(true);
        }
    }
}
 
Example 3
Source File: InventoryForItemStorage.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void inventoryClick(InventoryClickEvent event) {
	Inventory inventory = event.getClickedInventory();
	if (inventory != null) {
		InventoryAction action = event.getAction();
		if (action == InventoryAction.COLLECT_TO_CURSOR) {
			event.setCancelled(true);
		} else if (inventory.getType() == InventoryType.PLAYER) {
			if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
				event.setCancelled(true);
			}
		} else {
			event.setCancelled(true);
			int slot = event.getSlot();
			if (slot < ITEMS_PER_PAGE) {
				if (event.getCursor().getType() == Material.AIR && _originaItems[slot] != null) {
					event.getView().setCursor(_originaItems[slot]);
				}
			} else if (slot == 52) {
				// previous page
				changePage(-1);
			} else if (slot == 53) {
				// next page
				changePage(1);
			}
		}
	}
	
}
 
Example 4
Source File: MenuStored.java    From TabooLib with MIT License 4 votes vote down vote up
public void onClick(ClickEvent e) {
    if (e.getClickType() == ClickType.CLICK) {
        // 自动装填
        if (e.castClick().getClick().isShiftClick() && e.getRawSlot() >= e.getInventory().getSize() && Items.nonNull(e.getCurrentItem())) {
            e.setCancelled(true);
            // 获取有效位置
            int validSlot = getIntoSlot(e.getInventory(), e.getCurrentItem());
            if (validSlot >= 0) {
                // 设置物品
                intoItem(e.getInventory(), e.getCurrentItem(), validSlot);
                // 移除物品
                e.setCurrentItem(null);
                onClicked();
            }
        }
        // 手动装填
        else {
            // todo 合并物品
            if (e.castClick().getAction() == InventoryAction.COLLECT_TO_CURSOR) {
                e.setCancelled(true);
                return;
            }
            Action action;
            if (e.castClick().getClick().isShiftClick() && e.getRawSlot() >= 0 && e.getRawSlot() < e.getInventory().getSize()) {
                action = new ActionQuickTake();
            } else if (e.castClick().getClick() == org.bukkit.event.inventory.ClickType.NUMBER_KEY) {
                action = new ActionKeyboard();
            } else {
                action = new ActionClick();
            }
            // 点击有效位置
            if (isIntoSlot(e.getInventory(), action.getCurrent(e), action.getCurrentSlot(e))) {
                e.setCancelled(true);
                // 提取动作
                if (Items.isNull(action.getCurrent(e)) && existsItem(e.getInventory(), action.getCurrentSlot(e))) {
                    // 提取物品
                    action.setCurrent(e, getItem(e.getInventory(), action.getCurrentSlot(e)));
                    // 删除物品
                    intoItem(e.getInventory(), null, action.getCurrentSlot(e));
                    onClicked();
                }
                // 合法的位置
                else if (shouldIntoSlot(e.getInventory(), action.getCurrent(e), action.getCurrentSlot(e))) {
                    ItemStack current = action.getCurrent(e);
                    // 提取物品
                    action.setCurrent(e, getItem(e.getInventory(), action.getCurrentSlot(e)));
                    // 写入物品
                    intoItem(e.getInventory(), current, action.getCurrentSlot(e));
                    onClicked();
                }
            }
        }
    }
}
 
Example 5
Source File: InventoryGui.java    From InventoryGui with MIT License 4 votes vote down vote up
@EventHandler
private void onInventoryClick(InventoryClickEvent event) {
    if (event.getInventory().equals(getInventory(event.getWhoClicked()))) {

        int slot = -1;
        if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
            slot = event.getRawSlot();
        } else if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
            slot = event.getInventory().firstEmpty();
        }
    
        GuiElement.Action action = null;
        GuiElement element = null;
        if (slot >= 0) {
            element = getElement(slot);
            if (element != null) {
                action = element.getAction(event.getWhoClicked());
            }
        } else if (slot == -999) {
            action = outsideAction;
        } else {
            // Click was neither for the top inventory or outside
            // E.g. click is in the bottom inventory
            if (event.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
                simulateCollectToCursor(new GuiElement.Click(gui, slot, null, event.getClick(), event));
            }
            return;
        }
        try {
            if (action == null || action.onClick(new GuiElement.Click(gui, slot, element, event.getClick(), event))) {
                event.setCancelled(true);
                if (event.getWhoClicked() instanceof Player) {
                    ((Player) event.getWhoClicked()).updateInventory();
                }
            }
            if (action != null) {
                // Let's assume something changed and re-draw all currently shown inventories
                for (UUID playerId : inventories.keySet()) {
                    if (!event.getWhoClicked().getUniqueId().equals(playerId)) {
                        Player player = plugin.getServer().getPlayer(playerId);
                        if (player != null) {
                            draw(player);
                        }
                    }
                }
            }
        } catch (Throwable t) {
            event.setCancelled(true);
            if (event.getWhoClicked() instanceof Player) {
                ((Player) event.getWhoClicked()).updateInventory();
            }
            plugin.getLogger().log(Level.SEVERE, "Exception while trying to run action for click on "
                    + (element != null ? element.getClass().getSimpleName() : "empty element")
                    + " in slot " + event.getRawSlot() + " of " + gui.getTitle() + " GUI!");
            t.printStackTrace();
        }
    } else if (hasRealOwner() && owner.equals(event.getInventory().getHolder())) {
        // Click into inventory by same owner but not the inventory of the GUI
        // Assume that the underlying inventory changed and redraw the GUI
        plugin.getServer().getScheduler().runTask(plugin, (Runnable) gui::draw);
    }
}
 
Example 6
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());
            }
        }
    }
}