New answers tagged


Without the exact error I can only assume what the problem is. Both Player#getItemInHand(), ItemStack#getItemMeta() and ItemMeta#getDisplaName() can return null and thus can throw a nullpointer exception. You need to check if any of these is null before using them.


Instead of the this you need to pass an instance of the main class to the method. You can achieve this by using the constructor. When you create the Listener class (wich shouldn't be named listener BTW) you need to pass the instance of the main class to it. //Listener class <Main class> instance; public Listener(<Main class> instance) { this....


I hope this function gives you a raw idea on how it might work: // a couple of items to help out with the imagination Item apple = new Item("Apple"); Item sugar = new Item("Sugar"); Item peach = new Item("Peach"); Item marmelade = new Item("Marmelade"); Item banana= new Item("Banana"); Item milk= new Item("Milk"); Item shake = new Item("Banana Shake"); // ...

Top 50 recent answers are included