Hey, This is my code: Code (Text): @EventHandler public void onInventoryClickEvent(InventoryClickEvent e) { if (e.getInventory() instanceof CraftingInventory) { if (e.getCurrentItem().getType() == Material.BARRIER) { e.setCancelled(true); return; } } } There is one problem. When I jitterclick and close the inventory I can get the barrier out of the inventory. How can I disable/prevent this?
I'm pretty sure it's not. I forgot to mention that I want it to work on workbenches only (And maybe player crafting thingys)
just do e.getInventory().equals(e.getWhoClicked().getInventory()) and check e.getInventory() != null before
But that still doesnt prevent it from stealing Because the event gets canceled but when i click fast im able to craft the item
You could try changing the event priority to run first, and then cancel it at the very beginning of the event. Then don't cancel it if it is not in the circumstance you want.
Like this? Code (Text): @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClickEvent(InventoryClickEvent e) { e.setCancelled(true); if (e.getInventory() instanceof CraftingInventory) { if (e.getCurrentItem().getType() == Material.BARRIER) { e.setCancelled(true); return; } } e.setCancelled(false); } }
Code (Text): @EventHandler public void onPlayerBarrier(InventoryClickEvent e) { if (e.getClickedInventory() == null) return; if (!(e.getWhoClicked() instanceof Player)) return; Player player = (Player) e.getWhoClicked(); if (!e.getClickedInventory().equals(player.getInventory())) return; ItemStack item = e.getCurrentItem(); if (item == null) return; if (item.getType() == Material.AIR) return; // DO YOUR OTHER TEST HERE if (item.getType() == Material.BARRIER) { e.setCancelled(true); } } use this code it's work
Hey thanks for the code But I made this: Code (Text): @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClickEvent(InventoryClickEvent e) { e.setCancelled(true); if (e.getCurrentItem().getType() == Material.BARRIER) { if (e.getCurrentItem().hasItemMeta()) { if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ct.cc(main.getConfig().getString("CannotCraftItemName")))) { return; } } } e.setCancelled(false); } } Is this any better?