@Override @SuppressWarnings( "deprecation") // Player.updateInventory has been deprecated for a while with no alternative // available yet public void onClick(final InventoryClickEvent click) { final int last = click.getView().getTopInventory().getSize() - 1; // cancel shift clicks on items outside of delivery inventory to prevent indirect moving of // items into delivery inventory if (click.isShiftClick() && (click.getCurrentItem().getTypeId() != Material.AIR.getId()) && (click.getRawSlot() > last)) click.setCancelled(true); // cancel clicks with item on cursor in delivery inventory to prevent direct placement of items // into delivery inventory if ((click.getCursor().getTypeId() != Material.AIR.getId()) && (click.getRawSlot() >= 0) && (click.getRawSlot() <= last)) click.setCancelled(true); if (click.isCancelled()) { click.setCursor(click.getCursor()); ((Player) click.getWhoClicked()).updateInventory(); this.courier.send((Player) click.getWhoClicked(), "withdraw-only"); } }
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOWEST) public void onFurnaceInsert(InventoryClickEvent e) { if (e.getInventory().getType() == InventoryType.FURNACE && e.getCursor() != null && (e.getRawSlot() == 0 || e.getSlot() == 1)) { if (!e.isShiftClick()) { ItemStack item = e.getCurrentItem(); e.setCurrentItem(e.getCursor()); e.setCursor(item); e.setCancelled(true); PlayerInventory.update((Player) e.getWhoClicked()); } } }
@SuppressWarnings("deprecation") @EventHandler public void onInventoryClick(InventoryClickEvent e) { Player player = (Player) e.getWhoClicked(); Inventory inventory = e.getInventory(); ItemStack currentItem = e.getCurrentItem(); if (ArenaManager.getInstance().getArena(player) == null) { return; } Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player); if (!inventory.getName().equals(ChatColor.GREEN + "Options menu")) { return; } if (currentItem.getType() != Material.HARD_CLAY) { return; } if (!currentItem.hasItemMeta()) { return; } if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Floor block")) { return; } for (Block block : plot.getFloor().getAllBlocks()) { block.setType(e.getCursor().getType()); block.setData(e.getCursor().getData().getData()); } e.setCancelled(true); }
public static void debug(InventoryClickEvent event) { System.out.println("===== DEBUG START ====="); System.out.println("event.getAction() " + event.getAction()); System.out.println("event.isLeftClick() " + event.isLeftClick()); System.out.println("event.isRightClick() " + event.isRightClick()); System.out.println("event.isShiftClick() " + event.isShiftClick()); System.out.println("event.getClick() " + event.getClick()); System.out.println("event.getCurrentItem() " + event.getCurrentItem()); System.out.println("event.getCursor() " + event.getCursor()); System.out.println("event.getHotbarButton() " + event.getHotbarButton()); System.out.println("getInventory().getType() " + event.getInventory().getType()); System.out.println("event.getRawSlot() " + event.getRawSlot()); System.out.println("event.getResult() " + event.getResult()); System.out.println("event.getSlot() " + event.getSlot()); System.out.println("event.getSlotType() " + event.getSlotType()); System.out.println( "getView().getTopInventory().getType() " + event.getView().getTopInventory().getType()); System.out.println("getView().getType() " + event.getView().getType()); System.out.println( "getView().getBottomInventory().getType() " + event.getView().getBottomInventory().getType()); System.out.println("event.getWhoClicked() " + event.getWhoClicked()); System.out.println("-----"); System.out.println("isOutside(event) " + isOutside(event)); System.out.println("isTopInventory(event) " + isTopInventory(event)); System.out.println("isBottomInventory(event) " + isBottomInventory(event)); System.out.println("getAlter(event) " + getAlter(event)); System.out.println("isAltering(event) " + isAltering(event)); System.out.println("isEquipping(event) " + isEquipping(event)); System.out.println("===== DEBUG END ====="); }
/** * Handles attribute menu interaction * * @param event event details */ @EventHandler public void onClick(InventoryClickEvent event) { // Class selection if (InventoryManager.isMatching(event.getInventory(), MENU_KEY)) { // Do nothing when clicking outside the inventory if (event.getSlot() == -999) { return; } boolean top = event.getRawSlot() < event.getView().getTopInventory().getSize(); AttributeManager manager = SkillAPI.getAttributeManager(); // Interact with the skill tree when clicking in the top region if (top) { if (event.getSlot() < manager.getKeys().size() || event.getCursor() != null) { event.setCancelled(true); PlayerData data = SkillAPI.getPlayerData((Player) event.getWhoClicked()); if (event.isRightClick() && SkillAPI.getSettings().isAttributesDowngrade()) { data.refundAttribute(manager.getKeys().toArray()[event.getSlot()].toString()); } else if (event.isLeftClick()) { Object[] keys = manager.getKeys().toArray(); data.upAttribute(keys[event.getSlot()].toString()); } data.openAttributeMenu(); } } // Do not allow shift clicking items into the inventory else if (event.isShiftClick()) { event.setCancelled(true); } } }
@Override protected void onInventoryClick(InventoryClickEvent event, Player player) { event.setCancelled(true); final int slot = event.getRawSlot(); if (slot >= 0 && slot <= 7) { // handle changing sell stack size ItemStack item = event.getCurrentItem(); if (item != null && item.getType() != Material.AIR) { int amount = item.getAmount(); amount = this.getNewAmountAfterEditorClick(event, amount); if (amount <= 0) amount = 1; if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize(); item.setAmount(amount); } } else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) { if (((TradingPlayerShopkeeper) shopkeeper).clickedItem != null) { // placing item final Inventory inventory = event.getInventory(); Bukkit.getScheduler() .runTaskLater( ShopkeepersPlugin.getInstance(), new Runnable() { public void run() { inventory.setItem(slot, ((TradingPlayerShopkeeper) shopkeeper).clickedItem); ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null; } }, 1); } else { // changing stack size ItemStack item = event.getCurrentItem(); if (item != null && item.getType() != Material.AIR) { int amount = item.getAmount(); amount = this.getNewAmountAfterEditorClick(event, amount); if (amount <= 0) { event.getInventory().setItem(slot, null); } else { if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize(); item.setAmount(amount); } } } } else if (slot >= 27) { // clicking in player inventory if (event.isShiftClick() || !event.isLeftClick()) { return; } ItemStack cursor = event.getCursor(); if (cursor != null && cursor.getType() != Material.AIR) { return; } ItemStack current = event.getCurrentItem(); if (current != null && current.getType() != Material.AIR) { ((TradingPlayerShopkeeper) shopkeeper).clickedItem = current.clone(); ((TradingPlayerShopkeeper) shopkeeper).clickedItem.setAmount(1); } } else { super.onInventoryClick(event, player); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onInventoryClick(InventoryClickEvent e) { if (useLocaleInv && e.getView() instanceof LocaleInventory) { LocaleInventory inv = (LocaleInventory) e.getView(); InventoryClickEvent clickEvent = new InventoryClickEvent( inv.getView(), e.getSlotType(), e.getRawSlot(), e.isRightClick(), e.isShiftClick()); Bukkit.getServer().getPluginManager().callEvent(clickEvent); if (clickEvent.isCancelled()) { e.setCancelled(true); } else { switch (clickEvent.getResult()) { case DEFAULT: // Can't really do this with current events case ALLOW: System.out.println("ok..."); System.out.println(inv.getView().getItem(e.getRawSlot())); inv.getView().setItem(e.getRawSlot(), clickEvent.getCursor()); System.out.println(inv.getView().getItem(e.getRawSlot())); break; case DENY: break; } } for (LocaleInventory localeInv : localeInventories) { if (localeInv != inv) localeInv.reload(); } } }
@EventHandler(priority = EventPriority.NORMAL) public void onInventoryClick(InventoryClickEvent event) { if (!isItemInfoBook(event.getCursor())) { return; } if (!isPlace(event.getAction())) { return; } if (isInventory(event.getInventory())) { return; } if ((event.getRawSlot() - event.getView().getTopInventory().getSize()) >= 0) { return; } Module.sendMessage( "bInfoBooks", (Player) event.getWhoClicked(), "You can't store InfoBooks. Please drop the InfoBook to remove it from your inventory."); Module.sendMessage( "bInfoBooks", (Player) event.getWhoClicked(), "You can get another copy of the book via the '/book' command."); event.setResult(Result.DENY); }
protected static List<Entry<ItemStack, Integer>> getChangesClick(InventoryClickEvent event) { // Create List<Entry<ItemStack, Integer>> ret = new MassiveList<>(); // Fill final InventoryAlter alter = InventoryUtil.getAlter(event); final InventoryAction action = event.getAction(); ItemStack item; int amount; // Give if (alter.isGiving()) { // Special > MOVE_TO_OTHER_INVENTORY if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) { item = event.getCurrentItem(); ItemStack compare = item.clone(); compare.setAmount(1); amount = InventoryUtil.roomLeft(event.getInventory(), compare, item.getAmount()); } // Special > HOTBAR_SWAP else if (action == InventoryAction.HOTBAR_SWAP) { item = event.getView().getBottomInventory().getItem(event.getHotbarButton()); amount = item.getAmount(); } // Normal else { item = event.getCursor(); amount = item.getAmount(); if (action == InventoryAction.PLACE_ONE) { amount = 1; } else if (action == InventoryAction.PLACE_SOME) { int max = event.getCurrentItem().getType().getMaxStackSize(); amount = max - event.getCurrentItem().getAmount(); } } amount *= -1; ret.add(new SimpleEntry<ItemStack, Integer>(item, amount)); } // Take if (alter.isTaking()) { item = event.getCurrentItem(); amount = item.getAmount(); if (action == InventoryAction.PICKUP_ONE) amount = 1; if (action == InventoryAction.PICKUP_HALF) amount = (int) Math.ceil(amount / 2.0); ret.add(new SimpleEntry<ItemStack, Integer>(item, amount)); } // Return return ret; }
/** * Price managing for manager stock, this allows you to change prices for all items in your * traders stock * * @param e */ @ClickHandler( status = {tNpcStatus.MANAGE_PRICE}, inventory = InventoryType.TRADER) public void managePrices(InventoryClickEvent e) { // debug info dB.info("Price managing click event"); // select the item that should have the price changed if (selectAndCheckItem(e.getSlot())) { // show the current price in chat, if cursor is AIR if (e.getCursor().getTypeId() == 0) { // sends the message locale.sendMessage( player, "key-value", "key", "#price", "value", getSelectedItem().getPriceFormated()); } else { // adds the price attribute to the item Price price = getSelectedItem().getPriceAttr(); // adds value to the current price if (e.isLeftClick()) { // increases the price using specialBlockValue*cursorAmount price.increase(Settings.getBlockValue(e.getCursor()) * e.getCursor().getAmount()); // sends a message locale.sendMessage( player, "key-change", "key", "#price", "value", getSelectedItem().getPriceFormated()); } else // remove value from the current price if (e.isRightClick()) { // decreases the price using specialBlockValue*cursorAmount price.decrease(Settings.getBlockValue(e.getCursor()) * e.getCursor().getAmount()); // sends a message locale.sendMessage( player, "key-change", "key", "#price", "value", getSelectedItem().getPriceFormated()); } } } e.setCancelled(true); }
@EventHandler(ignoreCancelled = true) public void onFurnaceInsert(final InventoryClickEvent event) { if (event.getInventory().getType() != InventoryType.FURNACE) { return; } if (event.getRawSlot() == 0 && event.getCursor().getType() != Material.AIR) { if (!validateSmeltingIngredient(event.getCursor())) { event.setCancelled(true); } } else if (event.getRawSlot() >= event.getView().getTopInventory().getSize()) { if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { if (!validateSmeltingIngredient(event.getCurrentItem()) && !STBUtil.isFuel(event.getCurrentItem().getType())) { event.setCancelled(true); int newSlot = findNewSlot(event); if (newSlot >= 0) { event.getWhoClicked().getInventory().setItem(newSlot, event.getCurrentItem()); event.setCurrentItem(null); } } } } else if (event.getRawSlot() == 2 && SensibleToolbox.getItemRegistry().isSTBItem(event.getCurrentItem())) { // work around CB bug where shift-clicking custom items out of furnace seems // to cause a de-sync, leaving phantom items in the furnace Bukkit.getScheduler() .runTask( plugin, new Runnable() { @Override public void run() { STBUtil.forceInventoryRefresh(event.getInventory()); } }); } }
/** * This method will return the ItemStack the player is trying to equip. If the click event would * not result in equipping something null will be returned. Note that this algorithm is not * perfect. It's an adequate guess. * * @param event The InventoryClickEvent to analyze. * @return The ItemStack the player is trying to equip. */ public static ItemStack isEquipping(InventoryClickEvent event) { boolean isShiftClick = event.isShiftClick(); InventoryType inventoryType = event.getInventory().getType(); SlotType slotType = event.getSlotType(); ItemStack cursor = event.getCursor(); ItemStack currentItem = event.getCurrentItem(); if (isShiftClick) { if (inventoryType != InventoryType.CRAFTING) return null; if (slotType == SlotType.CRAFTING) return null; if (slotType == SlotType.ARMOR) return null; if (slotType == SlotType.RESULT) return null; if (currentItem.getType() == Material.AIR) return null; return currentItem; } else { if (slotType == SlotType.ARMOR) { return cursor; } return null; } }
@EventHandler public void onClickInventory(InventoryClickEvent ev) { if (ev.getInventory().getType() == InventoryType.HOPPER && ev.getInventory().getTitle().equalsIgnoreCase("Network Creator")) { if (ev.getCurrentItem() == null) { return; } if (ev.isShiftClick()) { ev.setCancelled(true); return; } if ((ev.getSlot() == 0 || ev.getSlot() == 1) && !CardNetworkListener.isModifier(ev.getCursor()) && ev.getCursor().getType() != Material.AIR) { ev.setCancelled(true); return; } if (ev.getSlot() == 3 && !pl.isCardNetwork(ev.getCursor()) && ev.getCursor().getType() != Material.AIR) { ev.setCancelled(true); return; } Player p = (Player) ev.getWhoClicked(); Inventory inv = ev.getInventory(); if (ev.getCurrentItem().getType() == Material.ENDER_PORTAL_FRAME && ev.getCurrentItem().hasItemMeta() && ev.getCurrentItem().getItemMeta().hasDisplayName() && ev.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§rDéassablage")) { ev.setCancelled(true); List<String> lore = ev.getCurrentItem().getItemMeta().getLore(); String[] cs = lore.get(0).split("/"); Block b = new Location( ev.getWhoClicked().getWorld(), Integer.parseInt(cs[0]), Integer.parseInt(cs[1]), Integer.parseInt(cs[2])) .getBlock(); b.setType(Material.AIR); pl.bs.remove(b); b.getWorld().dropItemNaturally(b.getLocation(), pl.nc); p.closeInventory(); return; } if (ev.getSlot() == 2 && ev.getCurrentItem().getType() == Material.STAINED_GLASS_PANE && ev.getCurrentItem().getDurability() == 15 && ev.getCurrentItem().hasItemMeta() && ev.getCurrentItem().getItemMeta().hasDisplayName() && ev.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§r--->")) { ev.setCancelled(true); if (inv.getItem(0) == null && inv.getItem(1) == null && inv.getItem(3) == null) return; if (CardNetworkListener.whatNetwork(inv.getItem(3)) != null) return; ItemStack item; ItemStack m1 = inv.getItem(0); ItemStack m2 = inv.getItem(1); if (m1 != null || m2 != null) { item = inv.getItem(3); ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.add(" "); lore.add(ChatColor.GRAY + "Modifier :"); if (m1 != null) { lore.add(ChatColor.GRAY + "- " + CardNetworkListener.whatModifier(m1)); inv.setItem(0, new ItemStack(Material.AIR)); } if (m2 != null && !m2.isSimilar(m1)) { lore.add(ChatColor.GRAY + "- " + CardNetworkListener.whatModifier(m2)); inv.setItem(1, new ItemStack(Material.AIR)); } im.setLore(lore); item.setItemMeta(im); inv.setItem(3, item); } p.playSound(p.getLocation(), Sound.WOOD_CLICK, 1, 1); Inventory icn = pl.getServer().createInventory(null, InventoryType.HOPPER, "NC"); icn.setContents(inv.getContents()); inv.clear(); new ChatInventory(pl, p, null, ChatEtat.CREATE_NETWORK, icn); p.closeInventory(); p.sendMessage(ChatColor.GRAY + "Entré le nom du réseau"); return; } } }
@SuppressWarnings("deprecation") @EventHandler public void onInventoryClick(InventoryClickEvent event) { // controller.getLogger().info("CLICK: " + event.getAction() + ", " + event.getClick() + " on " // + event.getSlotType() + " in "+ event.getInventory().getType() + " slots: " + event.getSlot() // + ":" + event.getRawSlot()); if (event.isCancelled()) return; if (!(event.getWhoClicked() instanceof Player)) return; Player player = (Player) event.getWhoClicked(); Mage apiMage = controller.getMage(player); if (!(apiMage instanceof com.elmakers.mine.bukkit.magic.Mage)) return; final com.elmakers.mine.bukkit.magic.Mage mage = (com.elmakers.mine.bukkit.magic.Mage) apiMage; GUIAction gui = mage.getActiveGUI(); if (gui != null) { gui.clicked(event); return; } // Check for temporary items and skill items InventoryAction action = event.getAction(); InventoryType inventoryType = event.getInventory().getType(); ItemStack clickedItem = event.getCurrentItem(); boolean isDrop = event.getClick() == ClickType.DROP || event.getClick() == ClickType.CONTROL_DROP; boolean isSkill = clickedItem != null && Wand.isSkill(clickedItem); // Preventing putting skills in containers if (isSkill && inventoryType != InventoryType.CRAFTING) { if (!isDrop) { event.setCancelled(true); } return; } // Check for right-click-to-use if (isSkill && action == InventoryAction.PICKUP_HALF) { Spell spell = mage.getSpell(Wand.getSpell(clickedItem)); if (spell != null) { spell.cast(); } player.closeInventory(); event.setCancelled(true); return; } if (clickedItem != null && NMSUtils.isTemporary(clickedItem)) { String message = NMSUtils.getTemporaryMessage(clickedItem); if (message != null && message.length() > 1) { mage.sendMessage(message); } ItemStack replacement = NMSUtils.getReplacement(clickedItem); event.setCurrentItem(replacement); event.setCancelled(true); return; } // Check for wearing spells ItemStack heldItem = event.getCursor(); if (heldItem != null && event.getSlotType() == InventoryType.SlotType.ARMOR) { if (Wand.isSpell(heldItem)) { event.setCancelled(true); return; } if (Wand.isWand(clickedItem) || Wand.isWand(heldItem)) { controller.onArmorUpdated(mage); } } boolean isHotbar = event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD; if (isHotbar && event.getSlotType() == InventoryType.SlotType.ARMOR) { int slot = event.getHotbarButton(); ItemStack item = mage.getPlayer().getInventory().getItem(slot); if (item != null && Wand.isSpell(item)) { event.setCancelled(true); return; } controller.onArmorUpdated(mage); } Wand activeWand = mage.getActiveWand(); boolean isChest = inventoryType == InventoryType.CHEST || inventoryType == InventoryType.HOPPER || inventoryType == InventoryType.DISPENSER || inventoryType == InventoryType.DROPPER; boolean clickedWand = Wand.isWand(clickedItem); boolean isContainerSlot = event.getSlot() == event.getRawSlot(); if (activeWand != null && activeWand.isInventoryOpen()) { // Kind of a hack to avoid hotbar items with 0 amounts disappearing :( Inventory inventory = player.getInventory(); for (int i = 0; i < 8; i++) { ItemStack item = inventory.getItem(i); if (item != null && item.getAmount() == 0) { item.setAmount(1); } } // Don't allow the offhand slot to be messed with while the spell inventory is open if (event.getRawSlot() == 45) { event.setCancelled(true); return; } if (Wand.isSpell(clickedItem) && clickedItem.getAmount() != 1) { clickedItem.setAmount(1); } if (clickedWand) { event.setCancelled(true); if (dropChangesPages) { activeWand.cycleInventory(); } else { activeWand.cycleHotbar(1); } return; } // So many ways to try and move the wand around, that we have to watch for! if (isHotbar && Wand.isWand(player.getInventory().getItem(event.getHotbarButton()))) { event.setCancelled(true); return; } // Can't wear spells if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) { if (controller.isWearable(clickedItem)) { event.setCancelled(true); return; } } // Safety check for something that ought not to be possible // but perhaps happens with lag? if (Wand.isWand(event.getCursor())) { activeWand.closeInventory(); event.setCursor(null); event.setCancelled(true); return; } } else if (activeWand != null) { // Check for changes that could have been made to the active wand Integer activeSlot = player.getInventory().getHeldItemSlot(); if (activeSlot != null && (event.getSlot() == activeSlot || (event.getAction() == InventoryAction.HOTBAR_SWAP && event.getHotbarButton() == activeSlot))) { mage.checkWand(); activeWand = mage.getActiveWand(); } } else if (clickedWand && Wand.Undroppable && !player.hasPermission("Magic.wand.override_drop") && isChest && !isContainerSlot) { Wand wand = new Wand(controller, clickedItem); if (wand.isUndroppable()) { event.setCancelled(true); return; } } // Check for armor changing if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) { if (controller.isWearable(clickedItem)) { controller.onArmorUpdated(mage); } } // Check for dropping items out of a wand's inventory // or dropping undroppable wands if (isDrop) { if (clickedWand) { Wand wand = new Wand(controller, clickedItem); if (wand.isUndroppable()) { event.setCancelled(true); if (activeWand != null) { if (activeWand.getHotbarCount() > 1) { activeWand.cycleHotbar(1); } else { activeWand.closeInventory(); } } return; } } if (activeWand != null && activeWand.isInventoryOpen()) { ItemStack droppedItem = clickedItem; if (!Wand.isSpell(droppedItem)) { mage.giveItem(droppedItem); event.setCurrentItem(null); event.setCancelled(true); return; } // This is a hack to deal with spells on cooldown disappearing, // Since the event handler doesn't match the zero-count itemstacks Integer slot = event.getSlot(); int heldSlot = player.getInventory().getHeldItemSlot(); Inventory hotbar = activeWand.getHotbar(); if (hotbar != null && slot >= 0 && slot <= hotbar.getSize() && slot != heldSlot && activeWand.getMode() == WandMode.INVENTORY) { if (slot > heldSlot) slot--; if (slot < hotbar.getSize()) { droppedItem = hotbar.getItem(slot); } else { slot = null; } } else { slot = null; } if (!controller.isSpellDroppingEnabled()) { player.closeInventory(); String spellName = Wand.getSpell(droppedItem); if (spellName != null && !activeWand.isManualQuickCastDisabled()) { Spell spell = mage.getSpell(spellName); if (spell != null) { activeWand.cast(spell); // Just in case a spell has levelled up... jeez! if (hotbar != null && slot != null) { droppedItem = hotbar.getItem(slot); } } } event.setCancelled(true); // This is needed to avoid spells on cooldown disappearing from the hotbar if (hotbar != null && slot != null && mage.getActiveGUI() == null) { player.getInventory().setItem(event.getSlot(), droppedItem); player.updateInventory(); } return; } ItemStack newDrop = controller.removeItemFromWand(activeWand, droppedItem); if (newDrop != null) { Location location = player.getLocation(); Item item = location.getWorld().dropItem(location, newDrop); item.setVelocity(location.getDirection().normalize()); } else { event.setCancelled(true); } } return; } // Check for wand cycling with active inventory if (activeWand != null) { WandMode wandMode = activeWand.getMode(); if ((wandMode == WandMode.INVENTORY && inventoryType == InventoryType.CRAFTING) || (wandMode == WandMode.CHEST && inventoryType == InventoryType.CHEST)) { if (activeWand.isInventoryOpen()) { if (event.getAction() == InventoryAction.NOTHING) { int direction = event.getClick() == ClickType.LEFT ? 1 : -1; activeWand.cycleInventory(direction); event.setCancelled(true); return; } if (event.getSlotType() == InventoryType.SlotType.ARMOR) { event.setCancelled(true); return; } // Chest mode falls back to selection from here. if (event.getAction() == InventoryAction.PICKUP_HALF || wandMode == WandMode.CHEST) { controller.onPlayerActivateIcon(mage, activeWand, clickedItem); player.closeInventory(); event.setCancelled(true); } } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void inventoryMenu(final InventoryClickEvent event) { // -------Armor wear handling-------- if (event.getSlotType() == SlotType.ARMOR && event.getClick() != ClickType.DOUBLE_CLICK) { CEventHandler.handleArmor( (Player) event.getWhoClicked(), event.getCurrentItem(), true, event); CEventHandler.handleArmor((Player) event.getWhoClicked(), event.getCursor(), false, event); if (event.getCursor() == null) CEventHandler.handleArmor( (Player) event.getWhoClicked(), event.getCurrentItem(), false, event); } else if (event.getClick() == ClickType.SHIFT_LEFT) { ItemStack current = event.getCurrentItem(); String typeS = current.getType().toString(); PlayerInventory inv = event.getWhoClicked().getInventory(); if ((typeS.endsWith("HELMET") && inv.getHelmet() == null) || (typeS.endsWith("CHESTPLATE") && inv.getChestplate() == null) || (typeS.endsWith("LEGGINGS") && inv.getLeggings() == null) || (typeS.endsWith("BOOTS") && inv.getBoots() == null)) CEventHandler.handleArmor( (Player) event.getWhoClicked(), event.getCurrentItem(), false, event); } // --------------------------------- if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || event.getRawSlot() < -1) { return; } if (event.getView().getTopInventory().getTitle().startsWith("CE")) { Inventory topInv = event.getView().getTopInventory(); final Player p = (Player) event.getWhoClicked(); ItemStack clickedItem = event.getCurrentItem(); event.setResult(Result.ALLOW); event.setCancelled(true); // This is the back-button, located in the very last spot of each inventory if ((event.getRawSlot() == topInv.getSize() - 1) && event.getCurrentItem().getType() != Material.AIR) { p.closeInventory(); p.openInventory(Tools.getPreviousInventory(topInv.getTitle())); return; } if (event.getRawSlot() < topInv.getSize()) { // Opens the clicked Enchantments inventory and loads the permissions if needed if (topInv.getTitle().equals(Tools.prefix + "Enchantments")) { p.closeInventory(); p.openInventory(Tools.getEnchantmentMenu(p, clickedItem.getItemMeta().getDisplayName())); return; } // Opens the item inventory and loads the permissions if needed if (topInv.getTitle().equals(Tools.prefix + "Main Menu") && event.getRawSlot() == 4) { p.closeInventory(); p.openInventory(Tools.getItemMenu(p)); return; } // These are the specific menus, clicking one of them will lead to the enchanting menu, // which needs to be 'notified' of the enchantment to give and it's cost if (topInv.getTitle().equals(Tools.prefix + "Global") || topInv.getTitle().equals(Tools.prefix + "Bow") || topInv.getTitle().equals(Tools.prefix + "Armor") || topInv.getTitle().equals(Tools.prefix + "Helmet") || topInv.getTitle().equals(Tools.prefix + "Boots") || topInv.getTitle().equals(Tools.prefix + "Tool")) if (p.isOp() || Tools.checkPermission( Tools.getEnchantmentByDisplayname(clickedItem.getItemMeta().getDisplayName()), p)) { Inventory enchantingMenu = Main.CEEnchantingMenu; enchantingMenu.setItem(0, clickedItem); p.closeInventory(); p.openInventory(enchantingMenu); return; } else { p.sendMessage( ChatColor.RED + "[CE] You do not have permission to buy this Enchantment."); return; } // This opens the Item Creation Menu if (topInv.getTitle().equals(Tools.prefix + "Items")) if (p.isOp() || Tools.checkPermission( Tools.getItemByDisplayname(clickedItem.getItemMeta().getDisplayName()), p)) { Inventory approveMenu = Main.CEApproveMenu; approveMenu.setItem(0, clickedItem); p.closeInventory(); p.openInventory(approveMenu); return; } else { p.sendMessage(ChatColor.RED + "[CE] You do not have permission to buy this Item."); return; } } if (topInv.getTitle().equals(Tools.prefix + "Enchanting") || topInv.getTitle().equals(Tools.prefix + "Item Creation")) { double cost = 0; ItemStack item = clickedItem; ItemMeta im = item.getItemMeta(); String type = ""; String successString = ""; Boolean itemSet = false; // TODO: Solve this by adding item-types // Swimsuit swimsuit = (Swimsuit) Main.items.get(9); if (topInv.getTitle().equals(Tools.prefix + "Enchanting")) { if (event.getRawSlot() > topInv.getSize() && event.isLeftClick()) { CEnchantment ce = Tools.getEnchantmentByDisplayname( topInv.getContents()[0].getItemMeta().getDisplayName()); cost = ce.getCost(); type = "enchantment " + ce.getDisplayName(); if (!ce.getApplication().equals(Application.GLOBAL) && !Tools.isApplicationCorrect(ce.getApplication(), clickedItem.getType())) { String appS = ce.getApplication().toString().toLowerCase(); p.sendMessage( ChatColor.RED + "[CE] This enchantment can only be applied to " + ChatColor.GRAY + (appS.endsWith("s") ? appS : appS + "s") + ChatColor.RED + "."); return; } List<String> lore = new ArrayList<String>(); if (clickedItem.getItemMeta().hasLore()) { lore = clickedItem.getItemMeta().getLore(); int number = 0; for (String s : lore) { CEnchantment c = Tools.getEnchantmentByDisplayname(s); if (c != null && c.originalName == ce.originalName) { p.sendMessage(ChatColor.RED + "[CE] This item already has this enchantment!"); return; } if (c != null) number++; } if (Main.maxEnchants > 0 && number >= Main.maxEnchants) { p.sendMessage( ChatColor.RED + "[CE] This item has already reached the maximum of " + ChatColor.GRAY + Main.maxEnchants + ChatColor.RED + " enchantments."); return; } } lore.add(ce.getDisplayName()); im.setLore(lore); item.setItemMeta(im); } else return; } else if (topInv.getTitle().equals(Tools.prefix + "Item Creation")) { item = topInv.getContents()[0]; cost = Tools.getItemByDisplayname(item.getItemMeta().getDisplayName()).getCost(); // if(item.hasItemMeta() && item.getItemMeta().hasDisplayName() && // item.getItemMeta().getDisplayName().equals(swimsuit.getDisplayName())) { //TODO: Always // keep the position of the Swimsuit updated // // // itemSet = true; // // int count = 0; // // for(ItemStack i : event.getView().getBottomInventory()) // if(i == null || i.getType().equals(Material.AIR)) // count++; // // if(count < 4) { // p.sendMessage(ChatColor.RED + "[CE] Your Inventory is full!"); // return; // } // // // } else { if (event.getView().getBottomInventory().firstEmpty() < 0) { p.sendMessage(ChatColor.RED + "[CE] Your Inventory is full!"); return; } // } ItemMeta itemIm = item.getItemMeta(); List<String> lore = itemIm.getLore(); lore.remove(lore.size() - 1); itemIm.setLore(lore); item.setItemMeta(itemIm); type = "item " + itemIm.getDisplayName(); } // TODO: Fix the cost for items // rewrite the whole section to check which enchantment or item is selected successString = (ChatColor.GREEN + "[CE] You have created the " + type + ChatColor.GREEN + "."); if (!p.isOp() && cost != 0) { if (Main.econ.getBalance(p.getName()) >= cost) { EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost); if (ecr.transactionSuccess()) successString = (ChatColor.GREEN + "[CE] Purchased " + type + ChatColor.GREEN + " for " + cost + " " + ((cost == 1) ? Main.econ.currencyNameSingular() : Main.econ.currencyNamePlural())); else { Bukkit.getConsoleSender() .sendMessage(ChatColor.RED + "[CE] An economy error has occured:"); Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage); p.closeInventory(); return; } } else { p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!"); p.closeInventory(); return; } } if (item != null) { if (!itemSet) if (type.startsWith("item") && event.getRawSlot() < topInv.getSize()) p.setItemInHand(item); else p.getInventory().setItem(event.getSlot(), item); // else { // ItemStack cp = item.clone(); // ItemStack le = item.clone(); // ItemStack bo = item.clone(); // // String[] parts = swimsuit.parts; // // cp.setType(Material.IRON_CHESTPLATE); // le.setType(Material.IRON_LEGGINGS); // bo.setType(Material.IRON_BOOTS); // // im.setDisplayName(parts[1]); // cp.setItemMeta(im); // im.setDisplayName(parts[2]); // le.setItemMeta(im); // im.setDisplayName(parts[3]); // bo.setItemMeta(im); // // p.getInventory().addItem(item); // p.getInventory().addItem(cp); // p.getInventory().addItem(le); // p.getInventory().addItem(bo); // // } } p.closeInventory(); p.sendMessage(successString); return; } if (event.getRawSlot() < topInv.getSize()) { p.closeInventory(); try { p.openInventory(Tools.getNextInventory(clickedItem.getItemMeta().getDisplayName())); } catch (Exception e) { p.sendMessage(ChatColor.RED + "[CE] This feature is disabled."); } } } }