Inventory clickevent problem

Discussion in 'Spigot Plugin Development' started by HoloGraphix-, May 29, 2015.

  1. Hi guys,

    I'm working on a GUI and had this issue ever since I started..

    Everytime I click INSIDE the inventory, doesn't matter where, everything works.. But if I click NEXT to the inventory (all arround the inventory) it gives an error..

    I'm using this code:
    Code (Text):
    if (e.getCurrentItem().getData().getItemType() == Material.BARRIER) {


    I hope I explained it well enough..

    Thanks already,
  2. Null check if the item is null
  3. I did that already actually, here:

    Code (Text):
                if (e.getCurrentItem().getData().getItemType() == null) {
                } else if (e.getCurrentItem().getData().getItemType() == Material.BARRIER) {
  4. Is that line 32 of your code?
  5. Just insert ! at the beginning :p
    • Useful Useful x 1
  6. Inkzzz

    Resource Staff

    Code (Text):
    if(e.getClickedInventory() == null) return;
    • Useful Useful x 1
  7. You guys are amazing!!
    • Like Like x 1
  8. Ik :p XD
  9. Inkzzz

    Resource Staff

    You're welcome.
  10. Code (Text):
    e.getCurrentItem().getData().getItemType() == null
    If getCurrentItem() returns null, calling getData() will cause a NullPointerException, just check if e.getCurrentItem() is null.
  11. I also suggest if using slots

    Code (Text):
    if(e.getSlot() == -1){
    because if no slot is clicked it returns -1
  12. I believe if you click next to your inventory getSlot() returns something like -999.
  13. I tested it, it is -1.