nullpointer

Discussion in 'Plugin Development' started by Nebula111, Jun 26, 2013.

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

    Nebula111

    Im having a problem below on line 17 (so the check if the item type is a gold ingot) The problem is I am able to right click with a block no problem, also no problem right clicking air with an empty hand; however I am getting a nullpointer when I right click a block with an empty hand. I also tried a check to see if the hand is empty but that didn't work. Its probably something really simple, but I cannot pinpoint it :( Thanks guys!

    Code:
    public class goldclicklistener implements Listener {
        @EventHandler(priority = EventPriority.HIGH)
        public void clickGoldEvent(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                if (e.getItem().getType() == Material.GOLD_INGOT){
                        p.getInventory().remove(Material.GOLD_INGOT);
                }
            }
        }
    }
    
     
  2. Offline

    chasechocolate

    Instead of event.getItem(), use player.getItemInHand().
     
  3. Offline

    Nebula111

    Thanks works perfectly!
     
Thread Status:
Not open for further replies.

Share This Page