Solved HELP | please help me resolve this problem!

Discussion in 'Spigot Plugin Development' started by eyalfx, May 17, 2016.

  1. Hello,
    Recently me and my friend was making a new plugin but suddenly we got an error.
    we tried to fix that error but it doesn't works, can anyone help?

    CODE: (if you can't find the line, this is the line:

    " if (((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) && (p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Kits Shop"))) ")

    Best wishes,

    ( btw: I dont know if this is the right forum to ask help ;{ )
  2. Code (Text):
    will return null if the player is not holding an item in their hand.

    Just do a null check first:
    Code (Text):
    if (((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) && (p.getItemInHand() != null && p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Kits Shop"))) ")
  3. nvm, thanks! I will check it now!! :D
  4. it doesnt works, any other ideas?
  5. Inkzzz

    Resource Staff

    Let me guess without even looking at the error: Either your item is null or the items meta is null or the items display-name is null.
    • Agree Agree x 1
  6. I will check, thanks for the help!! :)
  7. I think it might work !

    Code (Text):
    if(e.getAction() == Action.RIGHT_CLICK_AIR ||
       e.getAction() == Action.RIHGT_CLICK_BLOCK) {

         if(!(p.getItemInHand().hasItemMeta())) return;

         if(p.getItemInHand.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Kit Shop")) {
                //More code here