Java Code Examples for org.bukkit.event.inventory.ClickType#NUMBER_KEY

The following examples show how to use org.bukkit.event.inventory.ClickType#NUMBER_KEY . 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: BackpackListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
    ItemStack item = backpacks.get(e.getWhoClicked().getUniqueId());

    if (item != null) {
        SlimefunItem backpack = SlimefunItem.getByItem(item);

        if (backpack instanceof SlimefunBackpack) {
            if (e.getClick() == ClickType.NUMBER_KEY) {
                if (e.getClickedInventory().getType() != InventoryType.PLAYER) {
                    ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());

                    if (!isAllowed((SlimefunBackpack) backpack, hotbarItem)) {
                        e.setCancelled(true);
                    }
                }
            }
            else if (!isAllowed((SlimefunBackpack) backpack, e.getCurrentItem())) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 2
Source File: Servers.java    From TabooLib with MIT License 5 votes vote down vote up
public static List<ItemStack> getAffectItemInClickEvent(InventoryClickEvent e) {
    List<ItemStack> list = Lists.newArrayList();
    if (e.getClick() == ClickType.NUMBER_KEY) {
        Optional.ofNullable(e.getWhoClicked().getInventory().getItem(e.getHotbarButton())).ifPresent(list::add);
    }
    Optional.ofNullable(e.getCurrentItem()).ifPresent(list::add);
    return list;
}
 
Example 3
Source File: TestBackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(value = Material.class, names = { "AIR", "SHULKER_BOX" })
public void testHotbarKey(Material type) throws InterruptedException {
    Player player = server.addPlayer();
    openMockBackpack(player, "BACKPACK_HOTBAR_" + type.name(), 9);

    int slot = 7;
    player.getInventory().setItem(slot, new ItemStack(type));
    InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.NUMBER_KEY, InventoryAction.PICKUP_ONE, slot);
    listener.onClick(event);

    Assertions.assertEquals(type != Material.AIR, event.isCancelled());
}
 
Example 4
Source File: ArmorStandGUI.java    From ArmorStandTools with MIT License 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if(!event.getInventory().equals(i)) return;
    Player p = (Player) event.getWhoClicked();
    if(event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT || event.getClick() == ClickType.NUMBER_KEY) {
        event.setCancelled(true);
        return;
    }
    int slot = event.getRawSlot();
    if(slot > i.getSize()) return;
    if(invSlots.contains(slot)) {
        if(plugin.checkBlockPermission(p, as.getLocation().getBlock())) {
            updateInventory();
        } else {
            event.setCancelled(true);
            p.sendMessage(ChatColor.RED + Config.wgNoPerm);
        }
        return;
    }
    event.setCancelled(true);
    if(!(event.getWhoClicked() instanceof Player)) return;
    ArmorStandTool t = ArmorStandTool.get(event.getCurrentItem());
    if(t == null) return;
    if (!plugin.playerHasPermission(p, as.getLocation().getBlock(), t)) {
        p.sendMessage(ChatColor.RED + Config.generalNoPerm);
        return;
    }
    switch (t) {
        case INVIS:
            as.setVisible(!as.isVisible());
            Utils.actionBarMsg(p, Config.asVisible + ": " + (as.isVisible() ? Config.isTrue : Config.isFalse));
            break;
        case CLONE:
            p.closeInventory();
            plugin.pickUpArmorStand(Main.nms.clone(as), p, true);
            Utils.actionBarMsg(p, Config.carrying);
            break;
        case SAVE:
            if(Config.requireCreative && p.getGameMode() != GameMode.CREATIVE) {
                p.sendMessage(ChatColor.RED + Config.creativeRequired);
            } else {
                Main.nms.generateCmdBlock(p.getLocation(), as);
                Utils.actionBarMsg(p, Config.cbCreated);
            }
            break;
        case SIZE:
            as.setSmall(!as.isSmall());
            Utils.actionBarMsg(p, Config.size + ": " + (as.isSmall() ? Config.small : Config.normal));
            break;
        case BASE:
            as.setBasePlate(!as.hasBasePlate());
            Utils.actionBarMsg(p, Config.basePlate + ": " + (as.hasBasePlate() ? Config.isOn : Config.isOff));
            break;
        case GRAV:
            as.setGravity(!as.hasGravity());
            Utils.actionBarMsg(p, Config.gravity + ": " + (as.hasGravity() ? Config.isOn : Config.isOff));
            break;
        case ARMS:
            as.setArms(!as.hasArms());
            Utils.actionBarMsg(p, Config.arms + ": " + (as.hasArms() ? Config.isOn : Config.isOff));
            break;
        case NAME:
            p.closeInventory();
            plugin.setName(p, as);
            break;
        case PHEAD:
            p.closeInventory();
            plugin.setPlayerSkull(p, as);
            break;
        case INVUL:
            Utils.actionBarMsg(p, Config.invul + ": " + (Utils.toggleInvulnerability(as) ? Config.isOn : Config.isOff));
            break;
        case SLOTS:
            Utils.actionBarMsg(p, Config.equip + ": " + (Main.nms.toggleSlotsDisabled(as) ? Config.locked : Config.unLocked));
            break;
        case MOVE:
            p.closeInventory();
            UUID uuid = p.getUniqueId();
            if(plugin.carryingArmorStand.containsKey(uuid)) {
                plugin.carryingArmorStand.remove(uuid);
                Utils.actionBarMsg(p, Config.asDropped);
            } else {
                plugin.pickUpArmorStand(as, p, false);
                Utils.actionBarMsg(p, Config.carrying);
            }
            break;
        case GLOW:
            Utils.actionBarMsg(p, Config.glow + ": " + (Utils.toggleGlow(as) ? Config.isOn : Config.isOff));
            break;
        default:
            return;
    }
    i.setItem(t.getSlot(), updateLore(t));
}