Java 类org.bukkit.event.inventory.InventoryAction 实例源码

项目:uppercore    文件:HotbarManager.java   
@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();
    }

}
项目:RPGInventory    文件:ArmorEquipListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onQuickEquip(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    if (!InventoryManager.playerIsLoaded(player) || event.getAction() != Action.RIGHT_CLICK_AIR &&
            event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK &&
            !event.getClickedBlock().getState().getClass().getSimpleName().contains("BlockState")) {
        return;
    }

    ItemStack item = event.getItem();
    if (ItemUtils.isEmpty(item)) {
        return;
    }

    ArmorType armorType = ArmorType.matchType(item);
    if (InventoryUtils.playerNeedArmor(player, armorType)) {
        Slot armorSlot = SlotManager.instance().getSlot(armorType.name());
        if (armorSlot == null) {
            return;
        }

        event.setCancelled(!InventoryManager.validateArmor(player, InventoryAction.PLACE_ONE, armorSlot, item));

        PlayerUtils.updateInventory(player);
    }
}
项目:MCLibrary    文件:GUI.java   
@EventHandler
public void onClick(InventoryClickEvent e) {
    guiMap.getOptional(e.getWhoClicked()).ifPresent(gui -> {
        InventoryAction action = e.getAction();
        Inventory inv = e.getInventory();

        if (action == InventoryAction.COLLECT_TO_CURSOR) {
            for (ItemStack item : inv) {
                if (e.getCursor().isSimilar(item)) {
                    e.setCancelled(true);
                    break;
                }
            }
        }

        gui.getHandlers().notify(e);
    });
}
项目:QuestManager    文件:ContributionInventory.java   
@Override
public InventoryItem getItem(int pos, InventoryAction action) {
    //real logic is here
    /*
     * Check slot. If in player's inventory, try to take. If in top inventory, try and put back.
     */

    if (pos >= slots) {
        //in player's inventory
        doContribute(pos);
    } else if (pos == slots - 1) {
        doSubmit();
    } else {
        doReturn(pos);
    }


    return null; //tell it to do nothing
}
项目:ArmorStandTools    文件:MainListener.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) return;
    final Player p = (Player) event.getWhoClicked();
    ItemStack item = event.getCurrentItem();
    if(event.getInventory().getHolder() != p && ArmorStandTool.isTool(item)) {
        event.setCancelled(true);
        //noinspection deprecation
        p.updateInventory();
        return;
    }
    if(event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD) {
        if(Utils.hasItems(p)) {
            event.setCancelled(true);
            //noinspection deprecation
            p.updateInventory();
        }
    }
}
项目:sensibletoolbox    文件:AnvilListener.java   
@EventHandler
public void onAnvil(InventoryClickEvent event) {
    // The whole Anvil system is horribly broken right now, so we're just going to disallow
    // any kind of anvil activity for STB items.
    if (event.getWhoClicked() instanceof Player && event.getInventory().getType() == InventoryType.ANVIL) {
        if (event.getSlotType() == InventoryType.SlotType.CRAFTING) {
            if (SensibleToolbox.getItemRegistry().isSTBItem(event.getCursor())) {
                event.setCancelled(true);
                MiscUtil.errorMessage((Player) event.getWhoClicked(), "Sensible Toolbox items don't fit in a vanilla anvil.");
            }
        } else if (event.getRawSlot() > 2 && event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
            if (SensibleToolbox.getItemRegistry().isSTBItem(event.getCurrentItem())) {
                event.setCancelled(true);
                MiscUtil.errorMessage((Player) event.getWhoClicked(), "Sensible Toolbox items don't fit in a vanilla anvil.");
            }
        }
    }
}
项目:NucleusFramework    文件:ChestEventListener.java   
private ItemStackSource getRelevantStack(InventoryItemAction action, InventoryClickEvent event) {
    switch (action) {
        case PLACED_TOP:
            // fall through
        case PLACED_BOTTOM:
            // fall through
        case DROPPED:
            if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
                return ItemStackSource.SLOT;
            }

            return ItemStackSource.CURSOR;
        default:
            return ItemStackSource.SLOT;
    }
}
项目:NucleusFramework    文件:ChestViewTest.java   
/**
 * Make sure the "onItemsPickup" method is invoked when
 * items are picked up in the inventory view.
 */
@Test
public void testOnItemsPickup() {

    MockChestView view = new MockChestView(plugin, null);

    _session.next(view);
    BukkitTester.pause(2);

    BukkitTester.viewClick(player,
            SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PICKUP_ALL);

    BukkitTester.pause(2);

    // check "onItemsPickup" is invoked
    assertTrue(view.itemsPickup != null);
}
项目:NucleusFramework    文件:ChestViewTest.java   
/**
 * Make sure the "onItemsPlaced" method is invoked when
 * items are placed in the inventory view.
 */
@Test
public void testOnItemsPlaced() {
    MockChestView view = new MockChestView(plugin, null);

    _session.next(view);
    BukkitTester.pause(2);

    BukkitTester.viewClick(player,
            SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PLACE_ALL);

    BukkitTester.pause(2);

    // check "onItemsPlaced" is invoked
    assertTrue(view.itemsPlaced != null);
}
项目:NucleusFramework    文件:ChestViewTest.java   
/**
 * Make sure the "onItemsDropped" method is invoked when
 * items are dropped from the inventory view.
 */
@Test
public void testOnItemsDropped() {

    MockChestView view = new MockChestView(plugin, null);

    _session.next(view);
    BukkitTester.pause(2);

    BukkitTester.viewClick(player,
            SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.DROP_ALL_CURSOR);

    BukkitTester.pause(2);

    // check "onItemsDropped" is invoked
    assertTrue(view.itemsDropped != null);
}
项目:NucleusFramework    文件:MenuViewTest.java   
/**
 * Make sure {@link #onItemSelect} is invoked when a menu item is clicked
 * and that the correct {@link MenuItem} is passed into the invoked method.
 */
@Test
public void testOnItemSelected() {
    MockMenuView view = new MockMenuView(plugin, null);

    _session.next(view);
    BukkitTester.pause(2);

    MenuItem menuItem = new MenuItemBuilder(Material.WOOD).build(0);
    menuItem.setVisible(view, true);

    // select/click the menu item
    BukkitTester.viewClick(player,
            SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PICKUP_ALL);

    BukkitTester.pause(2);

    // check "onItemSelected" is invoked with correct menu item
    assertEquals(menuItem, view.selected);
}
项目:uppercore    文件:GuiManager.java   
@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);
    }
}
项目:SparseBukkitAPI    文件:ExampleMenu.java   
public ExampleMenu()
{
    super("Test Menu", 4);

    setItem(0, 0, new MenuItem()
    {
        public ItemStack getItem()
        {
            return new ItemBuilder(Material.PAPER).colorName("&a0,0").enchantEffect().build();
        }

        public boolean shouldUpdateItem()
        {
            return false;
        }

        public boolean onClick(Player player, ClickType clickType, InventoryAction action)
        {
            Bukkit.broadcastMessage(player.getName()+" clicked");
            return false;
        }
    });

    setItem(1,1, new BasicItem(
            new ItemBuilder(Material.PAPER).colorName("&a1,1").enchantEffect().build(),
            (player, clickType, action) ->
            {
                Bukkit.broadcastMessage(player.getName() + " clicked BasicItem");
                return false;
            })
    );
}
项目:ProjectAres    文件:ItemTransferListener.java   
@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;
    }
}
项目:SmartInvs    文件:InventoryManager.java   
@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));
    }
}
项目:RPGInventory    文件:MyPetManager.java   
public static boolean validatePet(
        Player player,
        InventoryAction action,
        @Nullable ItemStack currentItem,
        ItemStack cursor
) {
    ActionType actionType = ActionType.getTypeOfAction(action);
    boolean isAllowedAction = actionType == ActionType.GET
            || action == InventoryAction.SWAP_WITH_CURSOR
            || actionType == ActionType.DROP;

    return !(!ItemUtils.isEmpty(currentItem) && isAllowedAction)
            || swapMyPets(player, isMyPetItem(currentItem), cursor);
}
项目:RPGInventory    文件:InventoryManager.java   
public static void updateShieldSlot(@NotNull Player player, @NotNull Inventory inventory, @NotNull Slot slot, int slotId,
                                    InventoryType.SlotType slotType, InventoryAction action,
                                    ItemStack currentItem, ItemStack cursor) {
    ActionType actionType = ActionType.getTypeOfAction(action);
    if (actionType == ActionType.GET) {
        if (slot.isCup(currentItem)) {
            return;
        }

        if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
            inventory.setItem(slot.getSlotId(), slot.getCup());
        } else {
            player.getEquipment().setItemInOffHand(new ItemStack(Material.AIR));
        }
    } else if (actionType == ActionType.SET) {
        if (slot.isCup(currentItem)) {
            currentItem = null;
            action = InventoryAction.PLACE_ALL;
        }

        if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
            inventory.setItem(slot.getSlotId(), cursor);
        } else {
            player.getEquipment().setItemInOffHand(cursor);
        }
    }

    InventoryManager.updateInventory(player, inventory, slotId, slotType, action, currentItem, cursor);
}
项目:RPGInventory    文件:InventoryManager.java   
public static void updateQuickSlot(@NotNull Player player, @NotNull Inventory inventory, @NotNull Slot slot, int slotId,
                                   InventoryType.SlotType slotType, InventoryAction action,
                                   ItemStack currentItem, ItemStack cursor) {
    ActionType actionType = ActionType.getTypeOfAction(action);
    if (actionType == ActionType.GET) {
        if (slot.isCup(currentItem)) {
            return;
        }

        if (player.getInventory().getHeldItemSlot() == slot.getQuickSlot()) {
            InventoryUtils.heldFreeSlot(player, slot.getQuickSlot(), InventoryUtils.SearchType.NEXT);
        }

        if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
            inventory.setItem(slot.getSlotId(), slot.getCup());
        } else {
            player.getInventory().setItem(slot.getQuickSlot(), slot.getCup());
        }

        action = InventoryAction.SWAP_WITH_CURSOR;
        cursor = slot.getCup();
    } else if (actionType == ActionType.SET) {
        if (slot.isCup(currentItem)) {
            currentItem = null;
            action = InventoryAction.PLACE_ALL;
        }

        if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
            inventory.setItem(slot.getSlotId(), cursor);
        } else {
            player.getInventory().setItem(slot.getQuickSlot(), cursor);
        }
    }

    InventoryManager.updateInventory(player, inventory, slotId, slotType, action, currentItem, cursor);
}
项目:RPGInventory    文件:InventoryManager.java   
private static void updateInventory(
        @NotNull Player player,
        @NotNull Inventory inventory,
        int slot,
        InventoryAction action,
        ItemStack currentItem,
        @NotNull ItemStack cursor
) {
    InventoryManager.updateInventory(player, inventory, slot, InventoryType.SlotType.CONTAINER, action, currentItem, cursor);
}
项目:RPGInventory    文件:BackpackListener.java   
@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);
    }
}
项目:MCLibrary    文件:ClickHandler.java   
@Override
@SuppressWarnings("unchecked")
public void receive(GUIEvent event) {
    event.getEvent(GUIClickEvent.class).ifPresent(e -> {
        InventoryClickEvent clickEvent = (InventoryClickEvent) e;
        if (clickEvent.getAction() != InventoryAction.NOTHING &&
                (slots.isEmpty() || slots.contains(clickEvent.getRawSlot()))) {
            this.click(event);
        }
    });
}
项目:HamsterEcoHelper    文件:SignShopListener.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.getInventory().getHolder() instanceof ShopGUI) {
        event.setCancelled(true);
        if (event.getAction().equals(InventoryAction.PICKUP_ONE) ||
                event.getAction().equals(InventoryAction.PICKUP_ALL) ||
                event.getAction().equals(InventoryAction.PICKUP_HALF) ||
                event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
            Player player = (Player) event.getWhoClicked();
            ((ShopGUI) event.getInventory().getHolder()).onInventoryClick(event);
        } else {
            event.getWhoClicked().closeInventory();
        }
    }
}
项目:HamsterEcoHelper    文件:MarketListener.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.getInventory().getHolder() instanceof MarketGUI) {
        event.setCancelled(true);
        if (event.getAction().equals(InventoryAction.PICKUP_ONE) ||
                event.getAction().equals(InventoryAction.PICKUP_ALL) ||
                event.getAction().equals(InventoryAction.PICKUP_HALF) ||
                event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
            ((MarketGUI) event.getInventory().getHolder()).onInventoryClick(event);
        } else {
            event.getWhoClicked().closeInventory();
        }
    }
}
项目:QuestManager    文件:MiningGui.java   
@Override
public InventoryItem getItem(int pos, InventoryAction action) {
    if (this.backend == null) {
        return null;
    }

    if (this.gameState != State.RUNNING) {
        return null;
    }


    /*
     * Check slot. If mystery, just cancel.
     * If top or empty slot, ignore
     * otherwise, break block if dirt or break it down and update
     */
    int size = 9 * depth;

    if (pos > size) {
        return null;
    }

    if (hiddenMap.get(pos)) {
        return null;
    }

    //somewhere in the ground
    if (backend.containsKey(pos) && backend.get(pos) != BlockMaterial.AIR) {
        performHit(pos);
        update();
        return null;
    }


    return null; //tell it to do nothing
}
项目:QuestManager    文件:FashioningGui.java   
@Override
public InventoryItem getItem(int pos, InventoryAction action) {
    if (skillLink == null) 
        return null;

    /*
     * 0,1 are ingredient slots
     * 2 is result slot
     */

    if (pos == 2) {
        submit();
        player.updateInventory();
        return null;
    }

    if (pos > 2)
        submitItem(pos + 6);
    else {
        //ingredient slot. taking back?
        if (inv.getItem(pos) != null) {
            player.getInventory().addItem(inv.getItem(pos));
            inv.setItem(pos, null);
        }
    }

    QualityItem result = getResult(true);
    if (result == null) {
        inv.setItem(2, null);
        return null;
    }


    inv.setItem(2, result.getItem());

    return null; //tell it to do nothing
}
项目:Statz    文件:VillagerTradesListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVillagerTrade(final InventoryClickEvent event) {

    final PlayerStat stat = PlayerStat.VILLAGER_TRADES;

    // Thanks to Lolmewn for this code (https://bitbucket.org/Lolmewn/stats/src/4eae2db1b21038a91b7d39181f27bdd3cd987324/src/main/java/nl/lolmewn/stats/stats/bukkit/BukkitTrades.java?at=3.0&fileviewer=file-view-default)

    if (event.getInventory().getType() != InventoryType.MERCHANT) {
        return;
    }
    if (!event.getSlotType().equals(SlotType.RESULT)) {
        return;
    }
    if (!event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)
            && !event.getAction().equals(InventoryAction.PICKUP_ALL)) {
        return;
    }
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    ItemStack item = event.getCurrentItem();

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
            StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", item.getAmount(), "world",
                    player.getWorld().getName(), "trade", item.getType().toString()));

}
项目:Transformer    文件:PickBlockListener.java   
@EventHandler
public void onPick(InventoryCreativeEvent event){
    if(locked_players.containsKey(event.getWhoClicked())) {
        if (event.getClick().equals(ClickType.CREATIVE)) {
            if (event.getAction().equals(InventoryAction.PLACE_ALL)) {
                if (event.getCursor() != null) {
                    if (!event.getCursor().getType().equals(Material.AIR)) {
                        event.setCancelled(true);
                        locked_players.get(event.getWhoClicked()).changeBlock(new VirtualBlock(event.getCursor().getType()), (Player) event.getWhoClicked());
                    }
                }
            }
        }
    }
}
项目:rftd    文件:InventoryListener.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if(controller.isPlaying()) {
        boolean move = e.getRawSlot() >= e.getInventory().getSize()
                && e.getCurrentItem().getType() == Material.EYE_OF_ENDER
                && e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY;
        boolean inventory = e.getRawSlot() < e.getInventory().getSize()
                && e.getCursor().getType() == Material.EYE_OF_ENDER
                && e.getAction() != InventoryAction.PICKUP_ALL;

        if(move || inventory)
            e.setResult(Result.DENY);
    }
}
项目:NucleusFramework    文件:MenuItemTest.java   
/**
 * Make sure the on-click callbacks are run when the menu item
 * is clicked..
 */
@Test
public void testOnClick() throws Exception {

    MenuItem menuItem = new MenuItemBuilder(Material.STONE)
            .title("test")
            .onClick(new Runnable() {
                @Override
                public void run() {
                    _isOnClickRun = true;
                }
            })
            .build(0);

    MockMenuView view = new MockMenuView(plugin, null);
    ViewSession session = ViewSession.get(player, null);

    // open a menu view
    session.next(view);
    BukkitTester.pause(5);

    // set the item in the menu view
    menuItem.setVisible(view, true);
    BukkitTester.pause(5);

    // click the menu item
    BukkitTester.viewClick(player,
            SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PICKUP_ALL);
    BukkitTester.pause(5);

    // make sure the items on click runnables ran
    assertEquals(true, _isOnClickRun);
}
项目:NucleusFramework    文件:PaginatorViewTest.java   
/**
 * Make sure selecting a page works properly.
 */
@Test
public void testSelectPage() {

    ArrayListPaginator<String> paginator = new ArrayListPaginator<String>(PageStartIndex.ONE, 9);

    // add enough to produce 2 pages
    paginator.addAll(ArrayUtils.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"));

    PaginatorView view = new PaginatorView(plugin, paginator, null);

    // show the paginator to the player
    _session.next(view);
    BukkitTester.pause(5);

    // ensure that page 2 items are shown in the view
    assertTrue(view.getInventoryView().getItem(0) != null);
    assertTrue(view.getInventoryView().getItem(1) != null);
    assertTrue(view.getInventoryView().getItem(2) == null);

    // click on inventory slot index 1 (page 2)
    BukkitTester.viewClick(player,
            SlotType.CONTAINER, 1, ClickType.LEFT, InventoryAction.PICKUP_ALL);

    BukkitTester.pause(5);

    // make sure the paginator reports that page 2 was selected.
    assertEquals(2, view.getSelectedPage());

    // make sure paginator closes itself when page is selected
    assertEquals(null, _session.getCurrent());
}
项目:SparseBukkitAPI    文件:BasicItem.java   
public boolean onClick(Player player, ClickType clickType, InventoryAction action)
{
    if(onClick != null)
        return onClick.onClick(player, clickType, action);
    return false;
}
项目:SparseBukkitAPI    文件:EmptySlot.java   
public boolean onClick(Player player, ClickType clickType, InventoryAction action)
{
    return false;
}
项目:Kineticraft    文件:GUI.java   
/**
 * 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);
        }
    }
}
项目:RPGInventory    文件:InventoryManager.java   
public static boolean validateArmor(Player player, InventoryAction action, @NotNull Slot slot, ItemStack item) {
    ActionType actionType = ActionType.getTypeOfAction(action);
    return actionType != ActionType.OTHER && (actionType != ActionType.SET || slot.isValidItem(item))
            && ItemManager.allowedForPlayer(player, item, true);
}
项目:RPGInventory    文件:InventoryManager.java   
public static void updateArmor(@NotNull Player player, @NotNull Inventory inventory, @NotNull Slot slot, int slotId, InventoryAction action, ItemStack currentItem, @NotNull ItemStack cursor) {
    ActionType actionType = ActionType.getTypeOfAction(action);

    // Equip armor
    if (actionType == ActionType.SET || action == InventoryAction.UNKNOWN) {
        switch (slot.getName()) {
            case "helmet":
                InventoryManager.updateInventory(player, inventory, slotId, action, currentItem, cursor);
                player.getEquipment().setHelmet(inventory.getItem(slotId));
                break;
            case "chestplate":
                InventoryManager.updateInventory(player, inventory, slotId, action, currentItem, cursor);
                player.getEquipment().setChestplate(inventory.getItem(slotId));
                break;
            case "leggings":
                InventoryManager.updateInventory(player, inventory, slotId, action, currentItem, cursor);
                player.getEquipment().setLeggings(inventory.getItem(slotId));
                break;
            case "boots":
                InventoryManager.updateInventory(player, inventory, slotId, action, currentItem, cursor);
                player.getEquipment().setBoots(inventory.getItem(slotId));
                break;
        }
    } else if (actionType == ActionType.GET || actionType == ActionType.DROP) { // Unequip armor
        InventoryManager.updateInventory(player, inventory, slotId, action, currentItem, cursor);

        switch (slot.getName()) {
            case "helmet":
                player.getEquipment().setHelmet(null);
                break;
            case "chestplate":
                player.getEquipment().setChestplate(null);
                break;
            case "leggings":
                player.getEquipment().setLeggings(null);
                break;
            case "boots":
                player.getEquipment().setBoots(null);
                break;
        }
    }
}
项目:RPGInventory    文件:InventoryManager.java   
private static void updateInventory(
        @NotNull Player player,
        @NotNull Inventory inventory,
        int slot,
        InventoryType.SlotType slotType,
        InventoryAction action,
        ItemStack currentItem,
        ItemStack cursorItem
) {
    if (ActionType.getTypeOfAction(action) == ActionType.DROP) {
        return;
    }

    if (action == InventoryAction.PLACE_ALL) {
        if (ItemUtils.isEmpty(currentItem)) {
            currentItem = cursorItem.clone();
        } else {
            currentItem.setAmount(currentItem.getAmount() + cursorItem.getAmount());
        }

        cursorItem = null;
    } else if (action == InventoryAction.PLACE_ONE) {
        if (ItemUtils.isEmpty(currentItem)) {
            currentItem = cursorItem.clone();
            currentItem.setAmount(1);
            cursorItem.setAmount(cursorItem.getAmount() - 1);
        } else if (currentItem.getMaxStackSize() < currentItem.getAmount() + 1) {
            currentItem.setAmount(currentItem.getAmount() + 1);
            cursorItem.setAmount(cursorItem.getAmount() - 1);
        }
    } else if (action == InventoryAction.PLACE_SOME) {
        cursorItem.setAmount(currentItem.getMaxStackSize() - currentItem.getAmount());
        currentItem.setAmount(currentItem.getMaxStackSize());
    } else if (action == InventoryAction.SWAP_WITH_CURSOR) {
        ItemStack tempItem = cursorItem.clone();
        cursorItem = currentItem.clone();
        currentItem = tempItem;
    } else if (action == InventoryAction.PICKUP_ALL) {
        cursorItem = currentItem.clone();
        currentItem = null;
    } else if (action == InventoryAction.PICKUP_HALF) {
        ItemStack item = currentItem.clone();
        if (currentItem.getAmount() % 2 == 0) {
            item.setAmount(item.getAmount() / 2);
            currentItem = item.clone();
            cursorItem = item.clone();
        } else {
            currentItem = item.clone();
            currentItem.setAmount(item.getAmount() / 2);
            cursorItem = item.clone();
            cursorItem.setAmount(item.getAmount() / 2 + 1);
        }
    } else if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        player.getInventory().addItem(currentItem);
        currentItem = null;
    }

    if (slotType == InventoryType.SlotType.QUICKBAR) {
        if (slot < 9) { // Exclude shield
            player.getInventory().setItem(slot, currentItem);
        }
    } else {
        inventory.setItem(slot, currentItem);
    }

    player.setItemOnCursor(cursorItem);
    player.updateInventory();
}
项目:RPGInventory    文件:InventoryListener.java   
/**
 * 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);
    }
}
项目:RPGInventory    文件:ArmorEquipListener.java   
@EventHandler
public void onDispenseEquip(BlockDispenseEvent event) {
    ArmorType type = ArmorType.matchType(event.getItem());
    if (type != null) {
        Location blockLoc = event.getBlock().getLocation();
        for (Player player : blockLoc.getWorld().getPlayers()) {
            Location playerLoc = player.getLocation();
            if (blockLoc.getBlockY() - playerLoc.getBlockY() >= -1
                    && blockLoc.getBlockY() - playerLoc.getBlockY() <= 1) {
                if (type == ArmorType.HELMET && player.getInventory().getHelmet() == null
                        || type == ArmorType.CHESTPLATE && player.getInventory().getChestplate() == null
                        || type == ArmorType.LEGGINGS && player.getInventory().getLeggings() == null
                        || type == ArmorType.BOOTS && player.getInventory().getBoots() == null) {
                    org.bukkit.block.Dispenser dispenser = (org.bukkit.block.Dispenser) event.getBlock().getState();
                    org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData();
                    BlockFace directionFacing = dis.getFacing();
                    // Someone told me not to do big if checks because it's hard to read, look at me doing it -_-
                    if (directionFacing == BlockFace.EAST && playerLoc.getBlockX() != blockLoc.getBlockX()
                            && playerLoc.getX() <= blockLoc.getX() + 2.3 && playerLoc.getX() >= blockLoc.getX()
                            || directionFacing == BlockFace.WEST && playerLoc.getX() >= blockLoc.getX() - 1.3
                            && playerLoc.getX() <= blockLoc.getX()
                            || directionFacing == BlockFace.SOUTH
                            && playerLoc.getBlockZ() != blockLoc.getBlockZ()
                            && playerLoc.getZ() <= blockLoc.getZ() + 2.3 && playerLoc.getZ() >= blockLoc.getZ()
                            || directionFacing == BlockFace.NORTH && playerLoc.getZ() >= blockLoc.getZ() - 1.3
                            && playerLoc.getZ() <= blockLoc.getZ()) {
                        if (!InventoryManager.playerIsLoaded(player)) {
                            return;
                        }

                        Slot armorSlot = SlotManager.instance().getSlot(type.name());
                        event.setCancelled(armorSlot != null
                                && !InventoryManager.validateArmor(
                                player, InventoryAction.PLACE_ONE, armorSlot, event.getItem()));
                        return;
                    }
                }
            }
        }
    }
}
项目:MCLibrary    文件:GUIClickEvent.java   
@Override
public InventoryAction getAction() {
    return delegate.getAction();
}
项目:QuestManager    文件:FishingGui.java   
@Override
public InventoryItem getItem(int pos, InventoryAction action) {
    if (this.phase != GamePhase.RUNNING) {
        return null;
    }

    //real logic is here
    /*
     * Check slot. If in player's inventory, cancel.
     * If top slow, check if it's buttons, do action or nothing
     * Check if we have obstacle there. IF so, get rid of it
     */
    int size = 9 * (waterRows + 1);

    if (pos > size) {
        return null;
    }

    if (pos < 9) {
        //top bar. If 0, 8 it's a button
        if (pos == 0) {
            //stop reeling
            this.isReeling = false;
            player.playSound(player.getLocation(), CLICK_SOUND, 1, 1);
            return null;
        }
        if (pos == 8) {
            this.isReeling = true;
            player.playSound(player.getLocation(), CLICK_SOUND, 1, 1);
            return null;
        }
    }

    //somewhere in the water
    if (obstacles.containsKey(pos)) {
        player.playSound(player.getLocation(), WATER_SOUND, 1, 1);
        obstacles.remove(pos);
        inv.setItem(pos, waterIcon);

        if (obstacles.isEmpty()) {
            isStuck = false;
        }
    }


    return null; //tell it to do nothing
}