Solved What is returned by Player.getItemInHand() when the player isn't holding anything?

Discussion in 'Plugin Development' started by Nova Fusion, Jul 26, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Nova Fusion

    Welcome to my thread! yay! I need help with this. I know it's completely unrelated, but if you're some sort of genius Bukkit programmer guy, then I also need help changing costs of repairs/enchantments, and giving players additional range for melee attacks, breaking/placing blocks, etc.

    Anyway, yeah. Those things are completely unrelated, but if you know how to help me, that would be great!
     
  2. Offline

    Jade Retired Staff

    Moved to correct section.
     
  3. Offline

    Tirelessly

  4. Offline

    Nova Fusion

    player.getItemInHand().equals(null) is false though. Why is that?
     
  5. Offline

    Alex5657

    Thats not how you check for null. A null check is done by using "==". An equals() method is used to check equality of objects.
     
  6. Offline

    Tirelessly

    null.equals throws a nullpointer, and x.equals(null) is never true. Alex5657 is right.
     
  7. Offline

    Nova Fusion

    Code:
    player.getItemInHand() == null
    the above code returned false. Is there something I'm doing wrong? I DID make sure I wasn't holding anything.
     
  8. Offline

    soulofw0lf

    if (player.getItemInHand() == null || player.getItemInHand().getType().equals(Material.AIR)){
    //code
    }
     
  9. Offline

    Nova Fusion

    Oh wow! it worked! I was experimenting with air too, suspecting that was what was technically being held, but I didn't realize you had to throw in a getType() too. Thank you so much!
     
  10. Offline

    soulofw0lf

    np please remember to mark this as solved
     
Thread Status:
Not open for further replies.

Share This Page