Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#getClick()

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#getClick() . 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: ChestGUIListener.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
	Inventory inventory = CompatibilityUtils.getClickedInventory(event);
	if(inventory == null
			|| event.getCurrentItem() == null
			|| (!inventory.equals(event.getView().getTopInventory()) && event.getClick() != ClickType.SHIFT_LEFT && event.getClick() != ClickType.SHIFT_RIGHT)) {
		return;
	}

	Player player = (Player) event.getWhoClicked();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	GUIInventory guiInventory = nPlayer.getGuiInventory();

	if(guiInventory != null) {
		event.setCancelled(true);

		if(event.getSlot() == inventory.getSize() - 1 && event.getCurrentItem().equals(Message.INVENTORY_GUI_BACK.getItemStack())) {
			player.closeInventory();
			return;
		}

		if(event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) {
			guiInventory.onClick(event);
		}
	}
}
 
Example 2
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 3
Source File: VisitGUI.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (islands.containsKey(e.getSlot())) {
            Island island = IridiumSkyblock.getIslandManager().getIslandViaId(islands.get(e.getSlot()));
            User u = User.getUser((OfflinePlayer) e.getWhoClicked());
            if (island.isVisit() || u.bypassing) {
                if (e.getClick() == ClickType.RIGHT) {
                    if (island.hasVoted(u)) {
                        island.removeVote(u);
                    } else {
                        island.addVote(u);
                    }
                } else {
                    e.getWhoClicked().closeInventory();
                    island.teleportHome((Player) e.getWhoClicked());
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().playersIslandIsPrivate.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        } else if (e.getSlot() == getInventory().getSize() - 7) {
            if (IridiumSkyblock.visitGUI.containsKey(page - 1))
                e.getWhoClicked().openInventory(IridiumSkyblock.visitGUI.get(page - 1).getInventory());
        } else if (e.getSlot() == getInventory().getSize() - 3) {
            if (IridiumSkyblock.visitGUI.containsKey(page + 1))
                e.getWhoClicked().openInventory(IridiumSkyblock.visitGUI.get(page + 1).getInventory());
        }
    }
}
 
Example 4
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 5
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 6
Source File: IconMenu.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void onInventoryClick(InventoryClickEvent event) {       
    int index = invs.lastIndexOf(event.getInventory());
    if (index == -1) {
    	return;
    }

    event.setCancelled(true);

    int slot = event.getRawSlot();
 
    try {
        if (!(slot >= 0 && slot < invs.get(index).getSize())) {
            return;
        }
    } catch (NullPointerException e) {
    	return;
    }

    String name = "uselessName";
    if (event.getInventory().getItem(slot) != null && !event.getInventory().getItem(slot).getType().equals(Material.AIR)) {
        name = SkyWarsReloaded.getNMS().getItemName(event.getCurrentItem());
    }     

    if (!name.equalsIgnoreCase("uselessName")) {
        if (name.equalsIgnoreCase(SkyWarsReloaded.getNMS().getItemName(SkyWarsReloaded.getIM().getItem("prevPageItem")))) {
        	openInventory((Player) event.getWhoClicked(), index - 1);
        	return;
        }
        if (name.equalsIgnoreCase(SkyWarsReloaded.getNMS().getItemName(SkyWarsReloaded.getIM().getItem("nextPageItem"))) && index + 1 < invs.size()) {
        	openInventory((Player) event.getWhoClicked(), index + 1);
        	return;
        }
        OptionClickEvent clickEvent = new OptionClickEvent((Player) event.getWhoClicked(), name, event.getClick(), event.getCurrentItem().clone(), event.getRawSlot());
        handler.onOptionClick(clickEvent);
    }
}
 
Example 7
Source File: IntegerEditMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onClick(InventoryClickEvent event) {
    if (!(event.getInventory().getHolder() instanceof UltimateHolder) ||
            ((UltimateHolder) event.getInventory().getHolder()).getTitle() == null ||
            !stripFormatting(((UltimateHolder) event.getInventory().getHolder()).getTitle()).contains(stripFormatting(getTitle()))) {
        return false;
    }
    if (event.getSlotType() != InventoryType.SlotType.CONTAINER) {
        return true;
    }
    Player player = (Player) event.getWhoClicked();
    Inventory menu = event.getInventory();
    ItemStack returnItem = menu.getItem(getIndex(5, 0));
    String configName = returnItem.getItemMeta().getLore().get(0);
    String path = returnItem.getItemMeta().getLore().get(1);
    int page = getPage(returnItem.getItemMeta().getLore().get(2));
    int slot = event.getSlot();
    int row = slot / 9;
    int col = slot % 9;
    ItemStack clickedItem = event.getCurrentItem();
    if (slot >= getIndex(3, 0) && slot <= getIndex(3, 8)) {
        // increment buttons
        YmlConfiguration config = FileUtil.getYmlConfiguration(configName);
        int value = config.getInt(path, 0);
        int increment = getDisplayNameAsInt(clickedItem);
        if (event.getClick() == ClickType.LEFT) {
            value += increment;
        } else if (event.getClick() == ClickType.RIGHT) {
            value = increment;
        }
        config.set(path, value);
        config.set("dirty", true);
    }
    if (slot != getIndex(5,0)) {
        player.openInventory(createEditMenu(configName, path, page));
    } else {
        player.openInventory(parent.createEditMenu(configName, path, page));
    }
    return true;
}
 
Example 8
Source File: InventoryClick.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
public static InventoryClick fromClickEvent(final InventoryClickEvent event)
{
    return new InventoryClick(event.getInventory(), InventoryUtils.locateSlot(event.getRawSlot(), event.getClickedInventory().getType()), event.getClick());
}
 
Example 9
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));
}