Hi, my plugin crashes if i click outside of the inventory, or on an "Air" block. Code: http://pastebin.com/JTCBEk3b Please help me, and tell me where i should put the code, i am not that experienced.. Thanks in advance!!
Make a null check.... Not even needed. He doesn't check if the click or slot is null or air. Read post and code next time.
You don't check if the item is null You don't check if the item has item meta You don't check if the item meta has a display name
Check if inventory is not null Check if inventory name is not null Check if the click is not null I am not going to spoonfeed you, but you should check those before your code.
This is what I would use. I hope this is ok? Anyone think this is fine? Code (Text): if (e.getCurrentItem().getItemMeta() == null) { return; } Thx Pixl
Well normally when I register InventoryClickEvents, I only need two objects to make the code run smoothly. This for example is what I would use... Code (Text): @EventHandler public void onMyGui(InventoryClickEvent e){ Player p = (Player) e.getWhoClicked(); if (!e.getInventory().getName().equalsIgnoreCase(MyGui.GUI.getName())) { return; } if (e.getCurrentItem().getItemMeta() == null) { return; } //Then to get the individual item displayname if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Store")){ // Do Stuff in here ofc e.setCancelled(true); } Hope this helps, this is a really simple way of coding just so you know but for me it works. Thx Pixl
let's see Code (Java): void event { if(!e.getCurrentItem().hasItemMeta()) return; // check more check things // the event