@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onInventoryClick(final InventoryClickEvent event) { if(event instanceof InventoryCreativeEvent) return;; // Ensure the player is clicking in their own inventory // TODO: should we allow items to be locked into other types of inventories? if(!Objects.equals(event.getWhoClicked(), event.getInventory().getHolder())) return; // Break out of the switch if the action will move a locked item, otherwise return switch(event.getAction()) { case HOTBAR_SWAP: case HOTBAR_MOVE_AND_READD: // These actions can move up to two stacks. Check the hotbar stack, // and then fall through to check the stack under the cursor. if(isLocked(Slot.Hotbar.forPosition(event.getHotbarButton()) .getItem(event.getWhoClicked().getInventory()))) break; // fall through case PICKUP_ALL: case PICKUP_HALF: case PICKUP_SOME: case PICKUP_ONE: case SWAP_WITH_CURSOR: case MOVE_TO_OTHER_INVENTORY: case DROP_ONE_SLOT: case DROP_ALL_SLOT: case COLLECT_TO_CURSOR: // All these actions move only a single stack, except COLLECT_TO_CURSOR, // which can only move items that are stackable with the one under the cursor, // and locked items are only stackable with other locked items. if(isLocked(event.getCurrentItem())) break; // fall through default: return; } event.setCancelled(true); sendLockWarning(event.getWhoClicked()); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onInventoryCreative(InventoryCreativeEvent event) { HumanEntity humanEntity = event.getWhoClicked(); if (humanEntity instanceof Player && !humanEntity.hasPermission("base.command.gamemode")) { event.setCancelled(true); // humanEntity.sendMessage(ChatColor.RED + "You are not allowed to be in gamemode! Setting you to default gamemode!"); humanEntity.setGameMode(GameMode.SURVIVAL); } }
@EventHandler(priority = EventPriority.LOWEST) public void onCreativeSlotChange(InventoryCreativeEvent event) { if (timeouts.isEmpty()) { return; // Saves performance for most common case } InventoryHolder holder = event.getInventory().getHolder(); if (holder instanceof Player && timeouts.containsKey(((Player) holder).getUniqueId())) { event.setResult(Event.Result.DENY); } }
@EventHandler public void onPick(InventoryCreativeEvent event){ if(locked_players.containsKey(event.getWhoClicked())) { if (event.getClick().equals(ClickType.CREATIVE)) { if (event.getAction().equals(InventoryAction.PLACE_ALL)) { if (event.getCursor() != null) { if (!event.getCursor().getType().equals(Material.AIR)) { event.setCancelled(true); locked_players.get(event.getWhoClicked()).changeBlock(new VirtualBlock(event.getCursor().getType()), (Player) event.getWhoClicked()); } } } } } }
@EventHandler public void creativeInventory(InventoryCreativeEvent e) { if (e.getWhoClicked().hasPermission("commandspy.track")) { Runnable task = new CommandSpyFile(((Player) e.getWhoClicked()).getName(), "Inventory", "Own Inventory" + e.getAction() + "|" + e.getCurrentItem()); new Thread(task, "CommandSpy").start(); } }
@EventHandler(priority = EventPriority.HIGH) public void onCreative(InventoryCreativeEvent event) { try { Player p = (Player) event.getWhoClicked(); if (SGApi.getArenaManager().getArena(p).spectators.contains(p.getName())) event.setCancelled(true); } catch (ArenaNotFoundException ignored) {} }
@EventHandler public void creativeInventory(InventoryCreativeEvent e) { if (e.getWhoClicked().hasPermission("commandspy.track")) { final String name = e.getWhoClicked().getName(); final InventoryAction invAction = e.getAction(); final ItemStack item = e.getCurrentItem(); BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleAsyncDelayedTask(SQDuties.getPluginMain(), new Runnable() { @Override public void run() { (new CommandSpyFile(name, "Inventory", ("Own Inventory " + invAction + "|" + item))).run(); } },1); } }
@EventHandler(priority = EventPriority.HIGHEST) public void inventoryMenuPrevention(InventoryCreativeEvent event) { if (event.getView().getTopInventory().getTitle().startsWith("CE")) event.setCancelled(true); }
@EventHandler(priority = EventPriority.MONITOR) public void onViewingInventoryClick(InventoryCreativeEvent event) { updateNextTick(event.getActor()); }
@EventHandler public void onCreative(InventoryCreativeEvent evt) { ItemStack itemStack = evt.getCurrentItem(); ItemStack newStack = new ItemStack(itemStack.getType(), itemStack.getAmount()); evt.setCurrentItem(newStack); }
public void unregister() { InventoryCreativeEvent.getHandlerList().unregister(this); }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCreativeInventory(InventoryCreativeEvent evt) { plugin.getChecker().checkItem(evt.getCursor(), evt.getWhoClicked()); }
@Override public void unregister() { InventoryCreativeEvent.getHandlerList().unregister(this); }