NPE Help please

Discussion in 'Spigot Plugin Development' started by DidactCraft, May 28, 2015.

  1. alot of the error is missing, and are you using multicraft because some of it seems to be cut out?
     
  2. yea I'm using multicraft:

    http://pastebin.com/vxq78vRq

    Heres another one
     
  3. without the full uncut log, i cant really see what is the issue. It is something with InventoryClickEvent i know, but thats it as far as i can decode that error log
     
  4. Add a check to even see if it has ItemMeta

    I did something like this before and i did it without the check but when i added it the error stoped
     
  5. Can you show a example?
     
  6. @DidactCraft so. much. repetition. Also, you should not be closing the inventory in the InventoryClickEvent, as the documentation warns you that it could lead to unpredictable behaviour.
     
  7. Code (Text):
    if (!e.getCurrentItem().hasItemMeta()) {
        return;
    }
    Sorry if it is wrong just remembered it off the top of my head
     
  8. Wow, ok man. I want to close the inventory so the user can't abuse the kits. Also I've made it so that it opens another GUI.
     
  9. If a slot is not clicked, InventoryClickEvent#getSlot() will return -1, you should

    Code (Text):
    if(event.getSlot() == -1){
    event.setCancelled(true);
    }
     
  10. Thanks but what were you going to say after -- "you should" ?
     
  11. Ok I tried it, and its still throwing a NullPointerException on this line of code:
    if (e.getCurrentItem().getItemMeta().getDisplayName()
    .contains("ยง3Knight Kit")) {
    e.setCancelled(true);
    }
     
  12. Thanks man, I believed it worked! <3
     
  13. Trust me, it was the biggest pain when I had the same problem :/ e.getCurrentItem() without the method is just assuming there is an item.
     
  14. Thanks for your help <3
     
  15. Omnivion

    Patron

    Pretty sure there's a hasDisplayName() method as well.