当前位置: 首页>>代码示例>>Java>>正文


Java InventoryClickEvent.getAction方法代码示例

本文整理汇总了Java中org.bukkit.event.inventory.InventoryClickEvent.getAction方法的典型用法代码示例。如果您正苦于以下问题:Java InventoryClickEvent.getAction方法的具体用法?Java InventoryClickEvent.getAction怎么用?Java InventoryClickEvent.getAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.event.inventory.InventoryClickEvent的用法示例。


在下文中一共展示了InventoryClickEvent.getAction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPlayerClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    HotbarView h = view(player);
    if (e.getAction() == InventoryAction.HOTBAR_SWAP || e.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD) {
        //isIconSlot is really fast but it only works with the main player inventory where the first 9 indexes are
        //for the hotbar. this isn't exactly the main inventory but it works as well
        if (h != null && h.isIconSlot(e.getHotbarButton())) {
            e.setCancelled(true);
            return;
        }
    }

    if (h != null && (h.isIcon(e.getCurrentItem()) || h.isIcon((e.getCursor())))) {//TODO use normal slots
        e.setCancelled(true);
        player.updateInventory();
    }

}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:20,代码来源:HotbarManager.java

示例2: onInventoryClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
/**
 * Disable putting items in inventory
 *
 * @param event Click event instance
 */
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
    if (event.getClickedInventory() == null || !event.getClickedInventory().equals(this.inventory))
        return;

    switch (event.getAction())
    {
        case PICKUP_ALL:
        case PICKUP_HALF:
        case PICKUP_ONE:
        case PICKUP_SOME:
            event.setCancelled(false);
            break;

        default:
            event.setCancelled(true);
            break;
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:26,代码来源:RiskyRetrievalModule.java

示例3: onInventoryClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getClickedInventory() == e.getInventory())
        onClick(e);
    if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        if (getHistory((Player) e.getWhoClicked()) != null)
            e.setCancelled(true);
    }
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:10,代码来源:GuiManager.java

示例4: onInventoryClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
    if(event instanceof InventoryCreativeEvent) return;;

    // Ensure the player is clicking in their own inventory
    // TODO: should we allow items to be locked into other types of inventories?
    if(!Objects.equals(event.getWhoClicked(), event.getInventory().getHolder())) return;

    // Break out of the switch if the action will move a locked item, otherwise return
    switch(event.getAction()) {
        case HOTBAR_SWAP:
        case HOTBAR_MOVE_AND_READD:
            // These actions can move up to two stacks. Check the hotbar stack,
            // and then fall through to check the stack under the cursor.
            if(isLocked(Slot.Hotbar.forPosition(event.getHotbarButton())
                                   .getItem(event.getWhoClicked().getInventory()))) break;
            // fall through

        case PICKUP_ALL:
        case PICKUP_HALF:
        case PICKUP_SOME:
        case PICKUP_ONE:
        case SWAP_WITH_CURSOR:
        case MOVE_TO_OTHER_INVENTORY:
        case DROP_ONE_SLOT:
        case DROP_ALL_SLOT:
        case COLLECT_TO_CURSOR:
            // All these actions move only a single stack, except COLLECT_TO_CURSOR,
            // which can only move items that are stackable with the one under the cursor,
            // and locked items are only stackable with other locked items.
            if(isLocked(event.getCurrentItem())) break;

            // fall through

        default: return;
    }

    event.setCancelled(true);
    sendLockWarning(event.getWhoClicked());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:41,代码来源:ItemSharingAndLockingListener.java

示例5: setIgnoreDropFlag

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setIgnoreDropFlag(InventoryClickEvent event) {
    switch(event.getAction()) {
        case DROP_ALL_CURSOR:
        case DROP_ONE_CURSOR:
        case DROP_ALL_SLOT:
        case DROP_ONE_SLOT:
            // Make a note to ignore the PlayerDropItemEvent that will follow this one
            this.ignoreNextDropEvent = true;
            break;
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:13,代码来源:ItemTransferListener.java

示例6: collectToCursor

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@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;
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:9,代码来源:ItemTransferListener.java

示例7: onInventoryClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();

    if(!inventories.containsKey(p))
        return;

    if(e.getAction() == InventoryAction.COLLECT_TO_CURSOR ||
            e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        e.setCancelled(true);
        return;
    }

    if(e.getClickedInventory() == p.getOpenInventory().getTopInventory()) {
        e.setCancelled(true);

        int row = e.getSlot() / 9;
        int column = e.getSlot() % 9;

        if(row < 0 || column < 0)
            return;

        SmartInventory inv = inventories.get(p);

        if(row >= inv.getRows() || column >= inv.getColumns())
            return;

        inv.getListeners().stream()
                .filter(listener -> listener.getType() == InventoryClickEvent.class)
                .forEach(listener -> ((InventoryListener<InventoryClickEvent>) listener).accept(e));

        contents.get(p).get(row, column).ifPresent(item -> item.run(e));
    }
}
 
开发者ID:MinusKube,项目名称:SmartInvs,代码行数:35,代码来源:InventoryManager.java

示例8: onBackpackClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBackpackClick(final InventoryClickEvent event) {
    final Inventory inventory = event.getInventory();
    final Player player = (Player) event.getWhoClicked();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    if (inventory.getHolder() instanceof BackpackHolder) {
        // Click inside backpack
        if (BackpackManager.isBackpack(event.getCurrentItem())
                || BackpackManager.isBackpack(event.getCursor())
                || InventoryManager.isFilledSlot(event.getCurrentItem())
                || InventoryManager.isFilledSlot(event.getCursor())) {
            event.setCancelled(true);
            return;
        }

        // Save changes
        if (event.getAction() == InventoryAction.NOTHING) {
            return;
        }

        BackpackUpdater.update(inventory, InventoryManager.get(player).getBackpack());
    } else if ((event.getRawSlot() >= event.getView().getTopInventory().getSize()
            || event.getSlot() == SlotManager.instance().getBackpackSlot().getSlotId()
                    && InventoryAPI.isRPGInventory(event.getInventory()))
            && !BackpackManager.playerCanTakeBackpack(player)
            && BackpackManager.isBackpack(event.getCursor())
            && ActionType.getTypeOfAction(event.getAction()) == ActionType.SET) {
        // Prevent placing new backpack in bottom inventory if player can't take backpack
        int limit = BackpackManager.getLimit();
        String message = RPGInventory.getLanguage().getMessage("backpack.limit", limit);
        PlayerUtils.sendMessage(player, message);
        event.setCancelled(true);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:39,代码来源:BackpackListener.java

示例9: convert

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
private InventoryClickEvent convert(InventoryClickEvent event) {
    int rawSlot = event.getRawSlot();
    int convertedSlot = rawSlot - 9 + (currPage * spaceSize);
    return new InventoryClickEvent(
            event.getView(), event.getSlotType(), convertedSlot,
            event.getClick(), event.getAction(), event.getHotbarButton()
    );
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:9,代码来源:PageGUI.java

示例10: GUIClickEvent

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
public GUIClickEvent(InventoryClickEvent delegate, GUI gui) {
    super(delegate.getView(), delegate.getSlotType(), delegate.getRawSlot(), delegate.getClick(), delegate.getAction(), delegate.getHotbarButton());
    this.delegate = delegate;
    this.gui = gui;
    this.rawSlot = delegate.getRawSlot();
    this.slot = delegate.getSlot();
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:8,代码来源:GUIClickEvent.java

示例11: onClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
/**
 * Handle a player click.
 * @param evt
 */
public void onClick(InventoryClickEvent evt) {
    InventoryAction action = evt.getAction();
    if (IGNORE.contains(action)) {
        evt.setCancelled(true);
        return; // Don't allow these clicks.
    }

    Inventory top = evt.getView().getTopInventory();
    boolean isTop = top.equals(evt.getClickedInventory());
    boolean isBottom = evt.getView().getBottomInventory().equals(evt.getClickedInventory());
    ItemStack add = null;
    int slot = evt.getRawSlot();

    if (slot >= 0 && isTop) {
        GUIItem item = getItem(slot);
        if (item != null) {
            evt.setCancelled(true);
            item.onClick(evt);
        } else {
            if (!isAllowStorage()) {
                evt.setCancelled(true); // Don't allow depositing / withdrawing items.
                return;
            }

            if (action == InventoryAction.HOTBAR_MOVE_AND_READD || action == InventoryAction.HOTBAR_SWAP) {
                // Hotbar swap.
                if (item != null || !isAllowStorage()) // Either they're not allowed or they're swapping with a DisplayItem.
                    add = evt.getWhoClicked().getInventory().getItem(evt.getHotbarButton());
            } else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_ONE) { //PLACE_SOME adds to an existing stack, we only want to fire when a new item is added.
                add = evt.getCursor().clone();
                if (action == InventoryAction.PLACE_ONE)
                    add.setAmount(1); // They're right clicking an item in.
            }
        }
    } else if (isBottom && evt.isShiftClick()) { // They're trying to shift click an item in.
        if (isAllowStorage() && top.firstEmpty() > -1) {
            add = evt.getCurrentItem();
        } else {
            evt.setCancelled(true);
        }
    }

    if (add != null) {
        // We're depositing an item.
        if (canDeposit(slot, add)) {
            deposit(add);
        } else {
            evt.setCancelled(true);
        }
    }
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:56,代码来源:GUI.java

示例12: onArmorSlotClick

import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
/**
 * It happens when player click on armor slot
 */
private void onArmorSlotClick(InventoryClickEvent event, PlayerWrapper playerWrapper, final Slot slot,
                              ItemStack cursor, ItemStack currentItem) {
    final Player player = playerWrapper.getPlayer().getPlayer();
    final Inventory inventory = event.getInventory();
    final int rawSlot = event.getRawSlot();
    InventoryAction action = event.getAction();
    ActionType actionType = ActionType.getTypeOfAction(action);

    if (InventoryManager.validateArmor(player, action, slot, cursor) && playerWrapper.getInventoryView() != null) {
        // Event of equip armor
        InventoryClickEvent fakeEvent = new InventoryClickEvent(playerWrapper.getInventoryView(),
                InventoryType.SlotType.ARMOR, InventoryUtils.getArmorSlotId(slot), event.getClick(), action);
        Bukkit.getPluginManager().callEvent(fakeEvent);

        if (fakeEvent.isCancelled()) {
            event.setCancelled(true);
            return;
        }

        InventoryManager.updateArmor(player, inventory, slot, rawSlot, action, currentItem, cursor);

        if (actionType == ActionType.GET) {
            inventory.setItem(rawSlot, slot.getCup());
        } else if (slot.isCup(currentItem)) {
            player.setItemOnCursor(new ItemStack(Material.AIR));
        }

        player.updateInventory();
    }

    if (actionType == ActionType.DROP) {
        new BukkitRunnable() {
            @Override
            public void run() {
                inventory.setItem(rawSlot, slot.getCup());
                player.updateInventory();
            }
        }.runTaskLater(RPGInventory.getInstance(), 1);
    } else {
        event.setCancelled(true);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:46,代码来源:InventoryListener.java


注:本文中的org.bukkit.event.inventory.InventoryClickEvent.getAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。