@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); }
@EventHandler(priority = EventPriority.MONITOR) void onInventoryClick(InventoryClickEvent event) { if ((event.getInventory().getTitle().equals(this.name)) && (event.getWhoClicked().getName().equals(this.player.getName()))) { event.setCancelled(true); int slot = event.getRawSlot(); if ((slot >= 0) && (slot < this.size) && (this.optionNames[slot] != null)) { Plugin plugin = this.plugin; OptionClickEvent e = new OptionClickEvent((Player) event.getWhoClicked(), slot, this.optionNames[slot]); this.handler.onOptionClick(e); if (e.willClose()) { final Player p = (Player) event.getWhoClicked(); Bukkit.getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { public void run() { p.closeInventory(); } }, 1L); } if (e.willDestroy()) { destroy(); } } } }
@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"); } }
@EventHandler(priority = EventPriority.LOWEST) public void onInventoryClickEvent(final InventoryClickEvent event) { if (event.getView().getTopInventory().getType() == InventoryType.PLAYER) { final IUser user = userMap.getUser((Player)event.getWhoClicked()); final InventoryHolder invHolder = event.getView().getTopInventory().getHolder(); if (invHolder != null && invHolder instanceof Player) { final IUser invOwner = userMap.getUser((Player)invHolder); if (user.isInvSee() && (!Permissions.INVSEE_MODIFY.isAuthorized(user) || Permissions.INVSEE_PREVENT_MODIFY.isAuthorized( invOwner) || !invOwner.isOnline())) { event.setCancelled(true); } } } if (event.getView().getTopInventory().getType() == InventoryType.WORKBENCH) { final IUser user = userMap.getUser((Player)event.getWhoClicked()); if (user.isRecipeSee()) { event.setCancelled(true); } } }
public static void onInventoryClick(InventoryClickEvent e) { if (!(e.getWhoClicked() instanceof Player)) return; Player p = (Player) e.getWhoClicked(); if (gunBuilder.get(p) == true) { if (gunBuilderStep.get(p) >= 7) { e.setCancelled(true); } } }
@EventHandler public void onAnvil(InventoryClickEvent e) { if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) { if (SlimefunItem.getByItem(e.getInventory().getContents()[0]) != null) { e.setCancelled(true); Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); } } }
@EventHandler public void onInventoryClick(InventoryClickEvent event) { if (event.getInventory().getName() == "Choose a metal") { if (event.getRawSlot() <= 8) { event.getWhoClicked().getInventory().addItem(new ItemStack(event.getCurrentItem())); event.getWhoClicked().closeInventory(); event.setCancelled(true); } event.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 ====="); }
@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 + "Time selection")) { return; } if (currentItem.getType() != Material.WATCH) { return; } if (!currentItem.hasItemMeta()) { return; } if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "2 AM")) { return; } plot.setTime(Time.AM2); e.setCancelled(true); }
/** * 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); } } }
/** * Cancel players from removing, picking the hat in their inventory. * * @param EVENT */ @EventHandler public void cancelHatClick(final InventoryClickEvent EVENT) { if (EVENT.getCurrentItem() != null && EVENT.getCurrentItem().hasItemMeta() && EVENT.getCurrentItem().getItemMeta().hasDisplayName() && EVENT.getCurrentItem().getItemMeta().getDisplayName().equals("§8§oHat")) { EVENT.setCancelled(true); EVENT.setResult(Event.Result.DENY); EVENT.getWhoClicked().closeInventory(); Bukkit.getScheduler() .runTaskLaterAsynchronously( Core.getPlugin(), new Runnable() { @Override public void run() { for (ItemStack itemStack : EVENT.getWhoClicked().getInventory().getContents()) { if (itemStack != null && itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() && itemStack.getItemMeta().getDisplayName().equals("§8§oHat") && itemStack != EVENT.getWhoClicked().getInventory().getHelmet()) EVENT.getWhoClicked().getInventory().remove(itemStack); } } }, 1); } }
@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 + "Particles")) { return; } if (currentItem.getType() != Material.LAVA_BUCKET) { return; } if (!currentItem.hasItemMeta()) { return; } if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Lava drip")) { return; } plot.addParticle(new Particle(player.getLocation(), ParticleType.LAVA_DRIP)); e.setCancelled(true); }
@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); }
@EventHandler public void handleClick(InventoryClickEvent event) { if (event.getInventory().getName().equals(name)) { event.setCancelled(true); int slot = event.getRawSlot(); if (slot >= 0 && slot < size && items[slot] != null) { GUIClickEvent e = new GUIClickEvent(slot, (Player) event.getWhoClicked(), spawner); Bukkit.getPluginManager().callEvent(e); if (e.willClose()) { event.getWhoClicked().getOpenInventory().close(); } } } }
@EventHandler(priority = EventPriority.LOWEST) public void onMenuItemClicked(InventoryClickEvent event) { Inventory inventory = event.getInventory(); if (inventory.getHolder() instanceof InventoryMenu) { InventoryMenu menu = (InventoryMenu) inventory.getHolder(); if (event.getWhoClicked() instanceof Player) { Player player = (Player) event.getWhoClicked(); int index = event.getRawSlot(); if (index >= 0 && index < inventory.getSize()) { menu.selectItem(player, index, event.isRightClick(), event.isShiftClick()); } } event.setCancelled(true); } }
@Override public void onClicked(InventoryClickEvent event) { int newValue = value; if (event.isLeftClick()) { newValue -= event.isShiftClick() ? altIncr : incr; } else if (event.isRightClick()) { newValue += event.isShiftClick() ? altIncr : incr; } newValue = Math.max(Math.min(newValue, range.getMaximumInteger()), range.getMinimumInteger()); if (newValue != value && callback.run(newValue)) { value = newValue; event.setCurrentItem(getTexture()); } else { // vetoed by the block! if (event.getWhoClicked() instanceof Player) { STBUtil.complain((Player) event.getWhoClicked()); } } }
@EventHandler public void InvClickEvent(InventoryClickEvent event) { ItemStack selectedItem = event.getCurrentItem(); Player p = (Player) event.getWhoClicked(); Inventory inv = event.getInventory(); if (!inv.getName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "PLACE ITEMS BELOW")) { return; } if (selectedItem == null) { return; } if (selectedItem.getType().equals(Material.AIR)) { return; } if (selectedItem.getType().equals(Material.NETHER_FENCE) && selectedItem .getItemMeta() .getDisplayName() .equals(ChatColor.GRAY + "" + ChatColor.BOLD + "<--")) { event.setCancelled(true); } if (selectedItem.getType().equals(Material.STAINED_GLASS_PANE)) { if (selectedItem .getItemMeta() .getDisplayName() .equals(ChatColor.GREEN + "" + ChatColor.BOLD + "ACCEPT TRADE")) { event.setCancelled(true); tradeCountdown.put(event.getWhoClicked().getUniqueId(), 6); if (event .getInventory() .getItem(41) .getItemMeta() .getDisplayName() .equals(ChatColor.GREEN + "" + ChatColor.BOLD + "TRADE ACCEPTED")) { tradeCountdown.put(event.getWhoClicked().getUniqueId(), 6); } } } }
@EventHandler(ignoreCancelled = true) public void onPrefsMenuClick(InventoryClickEvent event) { Inventory inv = event.getInventory(); String name = inv.getTitle(); if (name.equals("§4TARDIS Key Prefs Menu")) { Player p = (Player) event.getWhoClicked(); int slot = event.getRawSlot(); if (slot >= 0 && slot < 27) { switch (slot) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 12: case 14: case 16: event.setCancelled(true); // set display name of key in slot 18 ItemStack key = inv.getItem(18); if (key == null || !key.getType().equals(Material.GOLD_NUGGET) || !key.hasItemMeta()) { return; } // get Display name of selected key ItemStack choice = inv.getItem(slot); ItemMeta choice_im = choice.getItemMeta(); String choice_name = choice_im.getDisplayName(); ItemMeta sonic_im = key.getItemMeta(); sonic_im.setDisplayName(choice_name); key.setItemMeta(sonic_im); break; case 18: break; case 26: // close event.setCancelled(true); close(p); break; default: event.setCancelled(true); break; } } else { ClickType click = event.getClick(); if (click.equals(ClickType.SHIFT_RIGHT) || click.equals(ClickType.SHIFT_LEFT)) { event.setCancelled(true); } } } }
@EventHandler public void onClick(InventoryClickEvent e) { if (e.getInventory() == null) return; if (e.getCurrentItem() == null) return; if (e.getCurrentItem().getType().equals(Material.AIR)) return; if (e.getInventory().getTitle() == null) return; if (e.getInventory().getTitle().equals(INV_TITLE)) { e.setCancelled(true); e.getWhoClicked().openInventory(e.getInventory()); } }
@EventHandler(priority = EventPriority.LOW) public void onInventoryClick(InventoryClickEvent event) { if (event.getWhoClicked() instanceof Player == false) { event.setCancelled(true); return; } Player player = (Player) event.getWhoClicked(); Client client = Client.getClient(player); if ((client.isObserver() || !Rixor.getRotation().getSlot().getMatch().isCurrentlyRunning()) && event.getInventory().getType() != InventoryType.PLAYER) { event.setCancelled(true); return; } if (!client.isObserver()) { /*Map map = Rixor.getRotation().getSlot().getMap(); */ } }
@EventHandler public void on(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); if (this.hasOpen(player)) { int slot = event.getSlot(); if (slot >= this.getSize()) { return; } event.setCancelled(true); getComponent(slot) .ifPresent( component -> { Position pos = this.components.get(component); Position xy = Position.toPosition(this, slot); component.onClick(player, event.getClick(), xy.x - pos.x, xy.y - pos.y); }); } }
@EventHandler public void onInventoryClick(InventoryClickEvent e) { if (!BookCoreFramework.getWindowManager() .getWindowHandler() .isWindowHolder((Player) e.getWhoClicked())) return; UIDisplaySession displaySession = BookCoreFramework.getWindowManager() .getSessionHandler() .getDisplaySession( BookCoreFramework.getWindowManager() .getSessionHandler() .getSession((Player) e.getWhoClicked())); Bukkit.getPluginManager() .callEvent( new WindowClickEvent( (Player) e.getWhoClicked(), displaySession.getWindow().getSystemName(), e, displaySession, "")); return; }
@EventHandler public void onInventoryClickEvent(InventoryClickEvent e) { Entity entity = e.getWhoClicked(); if (entity instanceof Player) { Player p = (Player) entity; if (Commands.tmpArmor.containsKey( p)) { // Don't let them throw away out armor if we're storing theirs! e.setCancelled(true); } } }
@EventHandler public void onInventroyClick(InventoryClickEvent event) { if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Offical MD Links")) ; return; Player player = (Player) event.getWhoClicked(); event.setCancelled(true); if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || !event.getCurrentItem().hasItemMeta()) { player.closeInventory(); return; } switch (event.getCurrentItem().getType()) { case BEACON: player.closeInventory(); player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/"); break; case ANVIL: player.closeInventory(); player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/"); break; case MINECART: player.closeInventory(); player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/"); break; case DIAMOND: player.closeInventory(); player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/"); break; case WOOL: player.closeInventory(); player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/"); break; case COMPASS: player.closeInventory(); player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/"); break; default: player.closeInventory(); break; } }
@EventHandler public void onArmorSlot(InventoryClickEvent e) { if (e.getSlotType().equals(InventoryType.SlotType.ARMOR)) { HumanEntity entity = (HumanEntity) e.getWhoClicked(); Player player = (Player) entity; String pn = player.getName(); String kit = Main.getKit().get(pn); if (kit.equalsIgnoreCase("hidden")) { e.setCancelled(true); } return; } return; }
@EventHandler public void onClick(InventoryClickEvent e) { if (Variables.backpack.containsKey(e.getWhoClicked().getUniqueId())) { ItemStack item = Variables.backpack.get(e.getWhoClicked().getUniqueId()); if (SlimefunManager.isItemSimiliar(item, SlimefunItems.COOLER, false)) { SlimefunItem sfItem = SlimefunItem.getByItem(e.getCurrentItem()); if (sfItem == null) e.setCancelled(true); else if (!(sfItem instanceof Juice)) e.setCancelled(true); } else if (SlimefunManager.isItemSimiliar(e.getCurrentItem(), item, true)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar( e.getCurrentItem(), SlimefunItems.BACKPACK_SMALL, false)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar( e.getCurrentItem(), SlimefunItems.BACKPACK_MEDIUM, false)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar( e.getCurrentItem(), SlimefunItems.BACKPACK_LARGE, false)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar( e.getCurrentItem(), SlimefunItems.WOVEN_BACKPACK, false)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar( e.getCurrentItem(), SlimefunItems.GILDED_BACKPACK, false)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar( e.getCurrentItem(), SlimefunItems.BOUND_BACKPACK, false)) e.setCancelled(true); } }
@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()); } } }
@EventHandler public void onInventoryClick(InventoryClickEvent event) { Inventory inventory = event.getInventory(); if (inventory.getName().equals(i.getName())) { event.setCancelled(true); Player player = (Player) event.getWhoClicked(); ItemStack stack = event.getCurrentItem(); if (stack == null || !stack.hasItemMeta()) return; if (stack.getItemMeta().getDisplayName().equals("Une pomme g閚iale !")) { player.closeInventory(); player.sendMessage( "Bravo, tu viens de cliquer sur " + stack.getItemMeta().getDisplayName() + " !"); player.addPotionEffect(PotionEffectType.FIRE_RESISTANCE.createEffect(Integer.MAX_VALUE, 2)); } } }
@EventHandler protected static void onInventoryClickEvent(InventoryClickEvent event) { if (event.getInventory().getName().equals(GUI_NAME)) { event.setCancelled(true); Player clicker = (Player) event.getWhoClicked(); ItemStack button = event.getClickedInventory().getItem(event.getSlot()); if (button.getType() == Material.REDSTONE_BLOCK) clicker.sendMessage(ChatColor.RED + "Error! This lobby is inactive at the moment!"); else { int lobbyID = Integer.parseInt(button.getItemMeta().getDisplayName().replace("Lobby ", "")); Lobby lobby = Lobby.getLobbies().get(lobbyID - 1); clicker.sendMessage(ChatColor.GREEN + "Joining lobby " + lobbyID + "..."); lobby.join(clicker); } } }
@EventHandler public void onInventoryClick(InventoryClickEvent ice) { Player player = (Player) ice.getWhoClicked(); Game game = Main.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() == GameState.WAITING) { this.onLobbyInventoryClick(ice, player, game); } if (game.getState() == GameState.RUNNING) { this.onIngameInventoryClick(ice, player, game); } }