Inventory Click Event Returning NullPointerException

Discussion in 'Spigot Plugin Development' started by RonanCraft, Apr 29, 2017.

  1. Every time I try to fix the menu side of my plugin it fails in some occasions, it's fine at ignoring click events from inventories such as a chest and vanilla stuff, but when other plugins come along, it has a hard time ignoring the click events. I wanted to ask if anyone knows of a way to completely ignore a click event if the inventory is not an instance of your menu class, I have no idea how to work with instances, but I just need a solution to all the errors in my console, it doesn't break anything, it just keeps error'ing out on color codes for some reason even though the command with the "exact" same color code line works just fine. And the actual inventory for the plugin works just fine, no idea what is causing this issue
     
  2. We don't know either without any provided code or errors.

    Make sure you
    1. Check if clicked inventory isnt null
    2. If the inventory has an name
    3. Then check the name
    4. Then check if item isnt null
    5. Then check if the item has an item meta.
    6. Then check the item meta and you should be good to go.

    Instead of using inventory.getname equals to ...
    You can use if inventory is equals the clicked one. You can skip part 1/2/3 then
     
    • Agree Agree x 1
  3. I think thats the problem (example):
    if(e.getClickedInventory() == null){
    return;
    }
    if(e.getClickedInventory().getName() == null){
    return;
    }
    if(e.getClickedInventory().getName().equals(INVENTORYNAME)){
    YOUR CODE
    }
     
  4. Why tho?

    This is much easier:

    Code (Text):
    if (e.getInventory().equals(inventory)) {

    //your code

    }
    No need for null checks. If the inventory is null then it just returns false.
     
  5. But if you click out of the inventory it will give an exception
     
  6. No, it wouldnt. The inventory would be null.
    See it like this:

    if (inventoryThatYouTryingToCompare == null)

    That just returns false. AKA skips that block, try it yourself :)
     
  7. Sorry for such a late reply, I've been trying to figure out why it keeps having errors. The error only happens when there is another GUI plugin on the server, but the plugin it self does not have an error line, it just says that the plugin could not pass a click event, almost as if the event did not happen in the first place? The plugin along on the server is fine, but just not with other menu plugins, any ideas?
     
  8. Contact the author of the other plugin?
     
  9. My plugin is the ONLY plugin that is doing this though, so it's a me problem xD darn I hate java so much
     
  10. Without any code/errors we can't provide you any help.
     
  11. The only error line is this "[Mon, 1. May 2017 11:40:55 ERROR] Could not pass event InventoryClickEvent to BetterBowTrails v1.8.1" that's basically it, no lines, it just plain out cancels the event