Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#isCancelled()
The following examples show how to use
org.bukkit.event.inventory.InventoryClickEvent#isCancelled() .
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: 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 2
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { if (event.isCancelled()) { return; } if (event.getClickedInventory() == null) { return; } if (event.getClickedInventory().getType() == InventoryType.PLAYER) { Player p = (Player) event.getWhoClicked(); if (Main.isPlayerInGame(p)) { GamePlayer gPlayer = Main.getPlayerGameProfile(p); Game game = gPlayer.getGame(); if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) { event.setCancelled(true); } } } }
Example 3
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { if (event.isCancelled()) { return; } if (event.getClickedInventory() == null) { return; } if (event.getClickedInventory().getType() == InventoryType.PLAYER) { Player p = (Player) event.getWhoClicked(); if (Main.isPlayerInGame(p)) { GamePlayer gPlayer = Main.getPlayerGameProfile(p); Game game = gPlayer.getGame(); if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) { event.setCancelled(true); } } } }
Example 4
Source File: LoreGuiItemListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW) public void OnInventoryClickSecondPhase(InventoryClickEvent event) { if (event.isCancelled()) { return; } if (event.getRawSlot() < event.getView().getTopInventory().getSize()) { if (guiInventories.containsKey(event.getView().getTopInventory().getName())) { event.setCancelled(true); return; } } else if (event.isShiftClick()) { if (guiInventories.containsKey(event.getView().getTopInventory().getName())) { event.setCancelled(true); return; } } }
Example 5
Source File: PlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
@Override protected void onPurchaseClick(InventoryClickEvent event, Player player, ItemStack[] usedRecipe, ItemStack offered1, ItemStack offered2) { super.onPurchaseClick(event, player, usedRecipe, offered1, offered2); if (event.isCancelled()) return; final PlayerShopkeeper shopkeeper = this.getShopkeeper(); if (Settings.preventTradingWithOwnShop && shopkeeper.isOwner(player) && !player.isOp()) { event.setCancelled(true); Log.debug("Cancelled trade from " + player.getName() + " because he can't trade with his own shop"); return; } if (Settings.preventTradingWhileOwnerIsOnline && !Utils.hasPermission(player, ShopkeepersAPI.BYPASS_PERMISSION)) { Player ownerPlayer = shopkeeper.getOwner(); if (ownerPlayer != null && !shopkeeper.isOwner(player)) { Utils.sendMessage(player, Settings.msgCantTradeWhileOwnerOnline, "{owner}", ownerPlayer.getName()); event.setCancelled(true); Log.debug("Cancelled trade from " + event.getWhoClicked().getName() + " because the owner is online"); return; } } }
Example 6
Source File: CustomMenu.java From Civs with GNU General Public License v3.0 | 5 votes |
public void onInventoryClick(InventoryClickEvent event) { Civilian civilian = CivilianManager.getInstance().getCivilian(event.getWhoClicked().getUniqueId()); ItemStack clickedItem = event.getCurrentItem(); if (!actions.containsKey(civilian.getUuid())) { return; } if (clickedItem == null || clickedItem.getType() == Material.AIR) { if (!event.isCancelled()) { event.setCancelled(true); } return; } List<String> actionStrings = actions.get(civilian.getUuid()).get(clickedItem.getType().name() + ":" + clickedItem.getItemMeta().getDisplayName()); if (actionStrings == null || actionStrings.isEmpty()) { if (!event.isCancelled()) { event.setCancelled(true); } return; } boolean shouldCancel = false; for (String actionString : actionStrings) { shouldCancel = doActionAndCancel(civilian, actionString, clickedItem) || shouldCancel; } if (!event.isCancelled()) { event.setCancelled(true); } }
Example 7
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onItemChange(InventoryClickEvent event) { if (event.isCancelled()) return; Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> { sendDurabilityBossBar((Player) event.getWhoClicked(), event.getWhoClicked().getInventory().getItemInMainHand(), EquipmentSlot.HAND); sendDurabilityBossBar((Player) event.getWhoClicked(), event.getWhoClicked().getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND); }); }
Example 8
Source File: TestBackpackListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private boolean isAllowed(String id, ItemStack item) throws InterruptedException { Player player = server.addPlayer(); Inventory inv = openMockBackpack(player, id, 9).getInventory(); int slot = 7; inv.setItem(slot, item); InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.LEFT, InventoryAction.PICKUP_ONE); listener.onClick(event); return !event.isCancelled(); }
Example 9
Source File: ListenerMenuAction.java From TrMenu with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onClick(InventoryClickEvent e) { Player p = (Player) e.getWhoClicked(); Notifys.debug(p, "Clicked raw slot §f{0}", e.getRawSlot()); long start = System.currentTimeMillis(); if (e.isCancelled() && TrMenu.SETTINGS.getBoolean("OPTIONS.IGNORE-CANCELLED")) { Notifys.debug(p, "Ignored cancelled"); return; } if (!(e.getInventory().getHolder() instanceof MenuHolder)) { Notifys.debug(p, "Not a MenuHolder"); return; } Menu menu = ((MenuHolder) e.getInventory().getHolder()).getMenu(); Button button = menu.getButton(p, e.getRawSlot()); // Anti ClickSpam clickTimes.putIfAbsent(p.getUniqueId(), 0L); if (System.currentTimeMillis() - clickTimes.get(p.getUniqueId()) < TrMenu.SETTINGS.getLong("OPTIONS.ANTI-CLICK-SPAM")) { e.setCancelled(true); Notifys.debug(p, "Anti-Spam, event cancelled."); return; } else { clickTimes.put(p.getUniqueId(), System.currentTimeMillis()); } if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY || e.getAction() == InventoryAction.HOTBAR_SWAP) { e.setCancelled(true); } // Lock PLayer's Inventory if (button == null) { if (e.getClickedInventory() == p.getInventory() && menu.isLockPlayerInv()) { e.setCancelled(true); } Notifys.debug(p, "Null button"); return; } else { e.setCancelled(true); } button.getIcon(p).onClick(p, button, e.getClick(), e); Notifys.debug(p, "§6InventoryClickEvent Took §e{0}ms§6.", System.currentTimeMillis() - start); }
Example 10
Source File: VaultBlacklistListener.java From Guilds with MIT License | 4 votes |
/** * Check if their item is on the vault blacklist * * @param event the click event */ @EventHandler public void onItemClick(InventoryClickEvent event) { // Check if the event was already cancelled before going through this all if (event.isCancelled()) { return; } // get the player who is clicking Player player = (Player) event.getWhoClicked(); // check if they are in the list of open vaults if (!guildHandler.getOpened().contains(player)) return; // get the item clicked ItemStack item = event.getCurrentItem(); // check if null if (item == null) return; // set cancelled if it contains material name event.setCancelled(settingsManager.getProperty(GuildVaultSettings.BLACKLIST_MATERIALS).stream().anyMatch(m -> m.equalsIgnoreCase(item.getType().name()))); // check if event is cancelled, if not, check name if (event.isCancelled()) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.VAULTS__BLACKLISTED); return; } // Make sure item has item meta if (!item.hasItemMeta()) return; // Check if it has a display name if (item.getItemMeta().hasDisplayName()) { // set cancelled if contains name event.setCancelled(settingsManager.getProperty(GuildVaultSettings.BLACKLIST_NAMES).stream().anyMatch(m -> m.equalsIgnoreCase(ACFBukkitUtil.removeColors(item.getItemMeta().getDisplayName())))); } // check if event is cancelled if (event.isCancelled()) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.VAULTS__BLACKLISTED); return; } // check if item has lore if (!item.getItemMeta().hasLore()) return; // set cancelled if contains lore List<String> lore = item.getItemMeta().getLore().stream() .map(ACFBukkitUtil::removeColors).collect(Collectors.toList()); // loop through string list for (String check : settingsManager.getProperty(GuildVaultSettings.BLACKLIST_LORES)) { // check if the lore contains it if (!check.equalsIgnoreCase("")) { if (lore.stream().anyMatch(l -> l.contains(check))) { // cancel the event event.setCancelled(true); break; } } } // check if event is cancelled, if not, check name if (event.isCancelled()) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.VAULTS__BLACKLISTED); } }
Example 11
Source File: ItemRenameListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onInventoryClick(InventoryClickEvent e) { // check if the event has been cancelled by another plugin if (!e.isCancelled()) { HumanEntity ent = e.getWhoClicked(); // not really necessary if (ent instanceof Player) { Player player = (Player) ent; Inventory inv = e.getInventory(); // see if the event is about an anvil if (inv instanceof AnvilInventory) { InventoryView view = e.getView(); int rawSlot = e.getRawSlot(); // compare the raw slot with the inventory view to make sure we are talking about the upper inventory if (rawSlot == view.convertSlot(rawSlot)) { /* slot 0 = left item slot slot 1 = right item slot slot 2 = result item slot see if the player clicked in the result item slot of the anvil inventory */ if (rawSlot == 2) { /* get the current item in the result slot I think inv.getItem(rawSlot) would be possible too */ ItemStack item = e.getCurrentItem(); // check if there is an item in the result slot if (item != null) { ItemMeta meta = item.getItemMeta(); // it is possible that the item does not have meta data if (meta != null) { // see whether the item is beeing renamed if (meta.hasDisplayName()) { String displayName = meta.getDisplayName(); ItemManager.setName(item, displayName); } } } } } } } } }
Example 12
Source File: BlueprintsMenu.java From Civs with GNU General Public License v3.0 | 4 votes |
@Override public void onInventoryClick(InventoryClickEvent event) { if (!event.isCancelled() && event.getCurrentItem() != null && !CVItem.isCivsItem(event.getCurrentItem())) { event.setCancelled(true); } }
Example 13
Source File: BookPlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override protected void onPurchaseClick(InventoryClickEvent event, Player player, ItemStack[] usedRecipe, ItemStack offered1, ItemStack offered2) { super.onPurchaseClick(event, player, usedRecipe, offered1, offered2); if (event.isCancelled()) return; final BookPlayerShopkeeper shopkeeper = this.getShopkeeper(); ItemStack book = usedRecipe[2]; String bookTitle = getTitleOfBook(book); if (bookTitle == null) { // this should not happen.. because the recipes were created based on the shopkeeper's offers event.setCancelled(true); return; } // get chest: Block chest = shopkeeper.getChest(); if (!Utils.isChest(chest.getType())) { event.setCancelled(true); return; } // remove blank book from chest: boolean removed = false; Inventory inv = ((Chest) chest.getState()).getInventory(); ItemStack[] contents = inv.getContents(); for (int i = 0; i < contents.length; i++) { if (contents[i] != null && contents[i].getType() == Material.BOOK_AND_QUILL) { if (contents[i].getAmount() == 1) { contents[i] = null; } else { contents[i].setAmount(contents[i].getAmount() - 1); } removed = true; break; } } if (!removed) { event.setCancelled(true); return; } // get price: BookOffer offer = shopkeeper.getOffer(bookTitle); if (offer == null) { event.setCancelled(true); return; } int price = this.getAmountAfterTaxes(offer.getPrice()); // add earnings to chest: if (price > 0) { int highCost = price / Settings.highCurrencyValue; int lowCost = price % Settings.highCurrencyValue; if (highCost > 0) { if (Utils.addItems(contents, Settings.createHighCurrencyItem(highCost)) != 0) { event.setCancelled(true); return; } } if (lowCost > 0) { if (Utils.addItems(contents, Settings.createCurrencyItem(lowCost)) != 0) { event.setCancelled(true); return; } } } // set chest contents: inv.setContents(contents); }
Example 14
Source File: BuyingPlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override protected void onPurchaseClick(InventoryClickEvent event, Player player, ItemStack[] usedRecipe, ItemStack offered1, ItemStack offered2) { super.onPurchaseClick(event, player, usedRecipe, offered1, offered2); if (event.isCancelled()) return; final BuyingPlayerShopkeeper shopkeeper = this.getShopkeeper(); // get offer for this bought item: ItemStack requestedItem = usedRecipe[0]; PriceOffer offer = shopkeeper.getOffer(requestedItem); if (offer == null) { // this should not happen.. because the recipes were created based on the shopkeeper's offers event.setCancelled(true); return; } int tradedItemAmount = offer.getItem().getAmount(); if (tradedItemAmount > requestedItem.getAmount()) { // this shouldn't happen .. because the recipe was created based on this offer event.setCancelled(true); return; } // get chest: Block chest = shopkeeper.getChest(); if (!Utils.isChest(chest.getType())) { event.setCancelled(true); return; } // remove currency from chest: Inventory inventory = ((Chest) chest.getState()).getInventory(); ItemStack[] contents = inventory.getContents(); boolean removed = this.removeCurrencyFromChest(offer.getPrice(), contents); if (!removed) { event.setCancelled(true); return; } // add items to chest: int amount = this.getAmountAfterTaxes(tradedItemAmount); if (amount > 0) { // the item the trading player gave might slightly differ from the required item, // but is still accepted, depending on item comparison and settings: ItemStack receivedItem = offered1.clone(); // create a copy, just in case receivedItem.setAmount(amount); if (Utils.addItems(contents, receivedItem) != 0) { event.setCancelled(true); return; } } // save chest contents: inventory.setContents(contents); }
Example 15
Source File: NormalPlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override protected void onPurchaseClick(InventoryClickEvent event, Player player, ItemStack[] usedRecipe, ItemStack offered1, ItemStack offered2) { super.onPurchaseClick(event, player, usedRecipe, offered1, offered2); if (event.isCancelled()) return; final NormalPlayerShopkeeper shopkeeper = this.getShopkeeper(); // get offer for this type of item: ItemStack resultItem = usedRecipe[2]; PriceOffer offer = shopkeeper.getOffer(resultItem); if (offer == null) { // this should not happen.. because the recipes were created based on the shopkeeper's offers event.setCancelled(true); return; } int tradedItemAmount = offer.getItem().getAmount(); if (tradedItemAmount != resultItem.getAmount()) { // this shouldn't happen .. because the recipe was created based on this offer event.setCancelled(true); return; } // get chest: Block chest = shopkeeper.getChest(); if (!Utils.isChest(chest.getType())) { event.setCancelled(true); return; } // remove result items from chest: Inventory inventory = ((Chest) chest.getState()).getInventory(); ItemStack[] contents = inventory.getContents(); contents = Arrays.copyOf(contents, contents.length); if (Utils.removeItems(contents, resultItem) != 0) { Log.debug("Chest does not contain the required items."); event.setCancelled(true); return; } // add earnings to chest: // TODO maybe add the actual items the trading player gave, instead of creating new currency items? int amount = this.getAmountAfterTaxes(offer.getPrice()); if (amount > 0) { if (Settings.highCurrencyItem == Material.AIR || offer.getPrice() <= Settings.highCurrencyMinCost) { if (Utils.addItems(contents, Settings.createCurrencyItem(amount)) != 0) { Log.debug("Chest cannot hold the given items."); event.setCancelled(true); return; } } else { int highCost = amount / Settings.highCurrencyValue; int lowCost = amount % Settings.highCurrencyValue; if (highCost > 0) { if (Utils.addItems(contents, Settings.createHighCurrencyItem(highCost)) != 0) { Log.debug("Chest cannot hold the given items."); event.setCancelled(true); return; } } if (lowCost > 0) { if (Utils.addItems(contents, Settings.createCurrencyItem(lowCost)) != 0) { Log.debug("Chest cannot hold the given items."); event.setCancelled(true); return; } } } } // save chest contents: inventory.setContents(contents); }