Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#getCurrentItem()
The following examples show how to use
org.bukkit.event.inventory.InventoryClickEvent#getCurrentItem() .
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: PickerMatchModule.java From PGM with GNU Affero General Public License v3.0 | 7 votes |
@EventHandler(priority = EventPriority.LOWEST) public void checkInventoryClick(final InventoryClickEvent event) { if (event.getCurrentItem() == null || event.getCurrentItem().getItemMeta() == null || event.getCurrentItem().getItemMeta().getDisplayName() == null) return; if (event.getWhoClicked() instanceof Player) { MatchPlayer player = match.getPlayer((Player) event.getWhoClicked()); if (player == null || !this.picking.contains(player)) return; this.handleInventoryClick( player, ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()), event.getCurrentItem().getData()); event.setCancelled(true); } }
Example 2
Source File: MainListener.java From ArmorStandTools with MIT License | 7 votes |
@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.hasAnyTools(p)) { event.setCancelled(true); //noinspection deprecation p.updateInventory(); } } }
Example 3
Source File: ObserverToolsMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onInventoryClick(final InventoryClickEvent event) { if (event.getCurrentItem() == null || event.getCurrentItem().getItemMeta() == null || event.getCurrentItem().getItemMeta().getDisplayName() == null) return; if (event.getWhoClicked() instanceof Player) { MatchPlayer player = match.getPlayer(event.getWhoClicked()); if (menu.isViewing(player)) { ItemStack clicked = event.getCurrentItem(); menu.getTools() .forEach( tool -> { if (clicked.getType().equals(tool.getMaterial(player))) { tool.onInventoryClick(menu, player, event.getClick()); } }); } } }
Example 4
Source File: MobSelector.java From CloudNet with Apache License 2.0 | 6 votes |
@EventHandler public void handleInventoryClick(InventoryClickEvent e) { if (!(e.getWhoClicked() instanceof Player)) { return; } if (inventories().contains(e.getInventory()) && e.getCurrentItem() != null && e.getSlot() == e.getRawSlot()) { e.setCancelled(true); if (ItemStackBuilder.getMaterialIgnoreVersion(mobConfig.getItemLayout().getItemName(), mobConfig.getItemLayout().getItemId()) == e.getCurrentItem().getType()) { MobImpl mob = find(e.getInventory()); if (mob.getServerPosition().containsKey(e.getSlot())) { if (CloudAPI.getInstance().getServerId().equalsIgnoreCase(mob.getServerPosition().get(e.getSlot()))) { return; } ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput(); byteArrayDataOutput.writeUTF("Connect"); byteArrayDataOutput.writeUTF(mob.getServerPosition().get(e.getSlot())); ((Player) e.getWhoClicked()).sendPluginMessage(CloudServer.getInstance().getPlugin(), "BungeeCord", byteArrayDataOutput.toByteArray()); } } } }
Example 5
Source File: BlockListeners.java From CratesPlus with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { if (!cratesPlus.getConfigHandler().isDisableKeySwapping() || event.getView().getTitle().equals("Claim Crate Keys")) return; if (!event.getInventory().getType().toString().contains("PLAYER") && event.getCurrentItem() != null) { String title; ItemStack item = event.getCurrentItem(); for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) { if (!(crate.getValue() instanceof KeyCrate)) { continue; } KeyCrate keyCrate = (KeyCrate) crate.getValue(); Key key = keyCrate.getKey(); if (key == null) continue; title = key.getName(); if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) { // Send message? event.setCancelled(true); return; } } } }
Example 6
Source File: ItemListener.java From HubBasics with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onItemMove(InventoryClickEvent event) { ItemStack currentItem = event.getCurrentItem(); if (currentItem == null || currentItem.getType() == Material.AIR) return; NBTItem nbtItem = new NBTItem(currentItem); if (!nbtItem.hasKey("HubBasics")) return; CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics")); if (item == null) { currentItem.setType(Material.AIR); // Destroy old item return; } if (item.getRunOnInventory()) { item.onCommand((Player) event.getWhoClicked()); } if (!item.getAllowMove()) event.setCancelled(true); // Call setCancelled only when needed to not conflict with other plugins }
Example 7
Source File: MenuClickListener.java From CS-CoreLib with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onClick(InventoryClickEvent e) { if (Maps.getInstance().menus.containsKey(e.getWhoClicked().getUniqueId())) { ChestMenu menu = Maps.getInstance().menus.get(e.getWhoClicked().getUniqueId()); if (e.getRawSlot() < e.getInventory().getSize()) { MenuClickHandler handler = menu.getMenuClickHandler(e.getSlot()); if(handler == null) { e.setCancelled(!menu.isEmptySlotsClickable() && (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)); } else { if (handler instanceof AdvancedMenuClickHandler) { e.setCancelled(!((AdvancedMenuClickHandler) handler).onClick(e, (Player) e.getWhoClicked(), e.getSlot(), e.getCursor(), new ClickAction(e.isRightClick(), e.isShiftClick()))); } else e.setCancelled(!handler.onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick()))); } } else e.setCancelled(!menu.getPlayerInventoryClickHandler().onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick()))); } else if (Maps.getInstance().inv.containsKey(e.getWhoClicked().getUniqueId())) { e.setCancelled(true); if (e.getCurrentItem() != null) { Bukkit.getPluginManager().callEvent(new MenuClickEvent((Player) e.getWhoClicked(), e.getInventory(), new ClickAction(e.isRightClick(), e.isShiftClick()), e.getSlot(), e.getCurrentItem(), e.getRawSlot())); } } }
Example 8
Source File: ChestGUIListener.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@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 9
Source File: KitLoading.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void StopClicking(InventoryClickEvent event) { HumanEntity entity = event.getWhoClicked(); ItemStack stack = event.getCurrentItem(); InventoryType top = event.getView().getTopInventory().getType(); if (stack != null && (entity instanceof Player)) { if (top == InventoryType.PLAYER || top == InventoryType.WORKBENCH || top == InventoryType.CRAFTING) return; if(KitUtils.isSoulbound(stack)) event.setCancelled(true); } }
Example 10
Source File: Gizmos.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void click(final InventoryClickEvent event) { if(event.getCurrentItem() == null) return; Player player = (Player) event.getWhoClicked(); if(!purchasingMap.containsKey(player)) return; Material clicked = event.getCurrentItem().getType(); for(Gizmo gizmo : gizmos) { if(clicked == gizmo.getIcon()) { player.closeInventory(); if(gizmo.ownsGizmo(player)) { GizmoUtils.setGizmo(player, gizmo, false); } else if(purchasingMap.containsKey(player)) { player.sendMessage(ChatColor.GOLD + LobbyTranslations.get().t("gizmo.currentlyPurchasing", player)); } else if(gizmo.canPurchase(player)) { GizmoUtils.openShop(player, gizmo); purchasingMap.put(player, gizmo); } else { player.sendMessage(gizmo.getNoPurchaseMessage(player)); } break; } } if(clicked == Material.DIAMOND) { GizmoUtils.purchaseGizmo(player, purchasingMap.get(player)); } else if(clicked == Material.REDSTONE_BLOCK) { GizmoUtils.cancelPurchase(player); } event.setCancelled(true); }
Example 11
Source File: NineSlotsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent e){ ItemStack item = e.getCurrentItem(); // Only handle clicked items. if (item == null){ return; } if (item.equals(fillItem)){ e.setCancelled(true); } }
Example 12
Source File: BasicGUIOpener.java From CratesPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { String title = event.getView().getTitle(); if (title.contains(" Win") && !title.contains("Edit ")) { if (event.getInventory().getType() == InventoryType.CHEST && event.getSlot() != 22 || event.getCurrentItem() != null) { event.setCancelled(true); event.getWhoClicked().closeInventory(); } } }
Example 13
Source File: PlayerListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) { Inventory inv = ice.getInventory(); ItemStack clickedStack = ice.getCurrentItem(); if (!inv.getTitle().equals(BedwarsRel._l(player, "lobby.chooseteam"))) { ice.setCancelled(true); return; } if (clickedStack == null) { ice.setCancelled(true); return; } if (clickedStack.getType() != Material.WOOL) { ice.setCancelled(true); return; } ice.setCancelled(true); Wool wool = (Wool) clickedStack.getData(); Team team = game.getTeamByDyeColor(wool.getColor()); if (team == null) { return; } game.playerJoinTeam(player, team); player.closeInventory(); }
Example 14
Source File: MobFlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) void onInventoryClick(InventoryClickEvent event) { InventoryHolder holder = event.getInventory().getHolder(); if (holder instanceof Player && holder.equals(this.player)) { if (event.getInventory().equals(this.player.getOpenInventory().getTopInventory())) { event.setCancelled(true); if (event.getRawSlot() == 0) { setFlagValue(true); close(true); return; } if (event.getRawSlot() == 1) { setFlagValue(false); close(true); return; } ItemStack item = event.getCurrentItem(); if (item != null && !item.equals(RedProtect.get().config.getGuiSeparator()) && !item.getType().equals(Material.AIR) && event.getRawSlot() >= 0 && event.getRawSlot() <= this.size - 1) { ItemMeta itemMeta = item.getItemMeta(); List<String> lore = itemMeta.getLore(); if (lore.get(0).equalsIgnoreCase(translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + RedProtect.get().guiLang.getFlagString("true")))) { lore.set(0, translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + RedProtect.get().guiLang.getFlagString("false"))); item.setAmount(1); } else { lore.set(0, translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + RedProtect.get().guiLang.getFlagString("true"))); item.setAmount(2); } itemMeta.setLore(lore); item.setItemMeta(itemMeta); } } } }
Example 15
Source File: VillagerTradesListener.java From Statz with GNU General Public License v3.0 | 5 votes |
@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())); }
Example 16
Source File: SpectateListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onInventoryClick(InventoryClickEvent e) { final Player player = (Player) e.getWhoClicked(); final GameMap gameMap = MatchManager.get().getSpectatorMap(player); if (gameMap == null) { return; } int slot = e.getSlot(); if (slot == 8) { player.closeInventory(); gameMap.getSpectators().remove(player.getUniqueId()); MatchManager.get().removeSpectator(player); } else if (slot >= 9 && slot <= 35) { player.closeInventory(); ItemStack item = e.getCurrentItem(); if (item != null && !item.getType().equals(Material.AIR)) { String name = ChatColor.stripColor(item.getItemMeta().getDisplayName()); Player toSpec = SkyWarsReloaded.get().getServer().getPlayer(name); if (toSpec != null) { if (!gameMap.mapContainsDead(toSpec.getUniqueId()) && player != null) { player.teleport(toSpec.getLocation(), TeleportCause.END_PORTAL); } } } } }
Example 17
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerInteractInventoryClick(InventoryClickEvent event) { final HumanEntity player = event.getWhoClicked(); GDCauseStackManager.getInstance().pushCause(player); if (!GDFlags.INTERACT_INVENTORY_CLICK || event.getClickedInventory() == null || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) { return; } GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.startTiming(); final Location location = player.getLocation(); final GDClaim claim = this.dataStore.getClaimAt(location); final ItemStack cursorItem = event.getCursor(); final Inventory source = event.getInventory(); final ItemStack target = event.getCurrentItem(); if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_INVENTORY_CLICK.getName(), target, player.getWorld().getUID())) { GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming(); return; } final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player.getUniqueId()); final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_INVENTORY_CLICK, source, target, user, TrustTypes.CONTAINER, true); if (result == Tristate.FALSE) { final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_INTERACT_ITEM, ImmutableMap.of( "player", claim.getOwnerDisplayName(), "item", ItemTypeRegistryModule.getInstance().getNMSKey(target))); GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message); event.setCancelled(true); } GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming(); }
Example 18
Source File: ButtonManager.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onClick(InventoryClickEvent event) { if(event.getCurrentItem() != null && onButtonClick(event.getCurrentItem(), event.getActor(), event.getClick(), event)) { event.setCancelled(true); } }
Example 19
Source File: InvClick.java From WildernessTp with MIT License | 4 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent e) { if (e.getInventory() == null) return; if (e.getView().getTitle() == null) return; if (e.getView().getTitle().equalsIgnoreCase("wildtp")) { if (e.getCurrentItem() == null) return; e.setCancelled(true); ItemStack item = e.getCurrentItem(); ItemMeta meta = item.getItemMeta(); String name = meta.getDisplayName().toUpperCase().replace("/","_").replace("-","_"); BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); name = name.replace(" ","_"); String toDo = ItemNames.valueOf(name).getSet(); switch (toDo.toLowerCase()){ case "hooks": e.getWhoClicked().closeInventory(); HookGui.openHook((Player) e.getWhoClicked()); break; case "back": e.getWhoClicked().closeInventory(); MainGui.OpenGUI((Player)e.getWhoClicked()); set.remove(e.getWhoClicked().getUniqueId()); add.remove(e.getWhoClicked().getUniqueId()); messages.remove(e.getWhoClicked().getUniqueId()); sounds.remove(e.getWhoClicked().getUniqueId()); break; case "close": scheduler.runTask(wild, () -> e.getWhoClicked().closeInventory()); MainGui.removeEdit((Player) e.getWhoClicked()); set.remove(e.getWhoClicked().getUniqueId()); add.remove(e.getWhoClicked().getUniqueId()); messages.remove(e.getWhoClicked().getUniqueId()); sounds.remove(e.getWhoClicked().getUniqueId()); break; case "add": e.getWhoClicked().closeInventory(); AddGui.openMessGui((Player) e.getWhoClicked()); add.add(e.getWhoClicked().getUniqueId()); break; case "messages": e.getWhoClicked().closeInventory(); MessageGui.openMessGui((Player) e.getWhoClicked()); messages.add(e.getWhoClicked().getUniqueId()); break; case "set": e.getWhoClicked().closeInventory(); SetGui.OpenSet((Player) e.getWhoClicked()); set.add(e.getWhoClicked().getUniqueId()); break; default: if(toDo.contains("Min")||toDo.contains("Max")) worlds.add(e.getWhoClicked().getUniqueId()); toSet.put(e.getWhoClicked().getUniqueId(),toDo); e.getWhoClicked().closeInventory(); break; } } }
Example 20
Source File: AdventurersGuildGUI.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onRankSelectorClick(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) return; if (!event.getInventory().getName().equalsIgnoreCase("Guild rank selector")) return; if (event.getCurrentItem() == null || event.getCurrentItem().getType().equals(Material.AIR)) return; event.setCancelled(true); if (!event.getClickedInventory().getName().equals("Guild rank selector")) { event.setCancelled(true); return; } int maxTier = PlayerData.playerMaxGuildRank.get(event.getWhoClicked().getUniqueId()); int selectedTier = event.getSlot() + 1; if (selectedTier < maxTier + 1) { PlayerData.playerSelectedGuildRank.put(event.getWhoClicked().getUniqueId(), selectedTier); difficultyMenu((Player) event.getWhoClicked()); } if (selectedTier == maxTier + 1) { if (EconomyHandler.checkCurrency(event.getWhoClicked().getUniqueId()) < tierPriceCalculator(selectedTier)) event.getWhoClicked().sendMessage("[EliteMobs] You don't have enough Elite Coins! Sell some Elite Mob loot to [/em shop]!"); else { EconomyHandler.subtractCurrency(event.getWhoClicked().getUniqueId(), tierPriceCalculator(selectedTier)); PlayerData.playerMaxGuildRank.put(event.getWhoClicked().getUniqueId(), selectedTier); event.getWhoClicked().sendMessage(ChatColorConverter.convert("&aYou have unlocked the " + rankNamer(selectedTier) + " &arank for " + tierPriceCalculator(selectedTier) + " " + ConfigValues.economyConfig.getString(EconomySettingsConfig.CURRENCY_NAME) + ". \n&6Happy hunting!")); difficultyMenu((Player) event.getWhoClicked()); Bukkit.broadcastMessage(ChatColorConverter.convert( ((Player) event.getWhoClicked()).getDisplayName() + " has reached the " + rankNamer(selectedTier) + " &fguild rank!")); if (ConfigValues.adventurersGuildConfig.getBoolean(AdventurersGuildConfig.ADD_MAX_HEALTH)) event.getWhoClicked().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue((selectedTier - 10) * 2 + 20); } } if (selectedTier > maxTier + 1) { event.getWhoClicked().sendMessage("[EliteMobs] You need to unlock other ranks first!"); } }