Solved NullPointer at PlayerInteractEvent

Discussion in 'Spigot Plugin Development' started by ScorixEar, May 29, 2016.

  1. Hi guys, I want to check, if the player does a rightclick with a slimeblock in air or on block and hold a golden apple in the left hand (so the new slot since 1.9) and eat them. The result was a nullpointerexception in the if e.getItem() line. Any ideas?
    Code (Text):
    public class RightClickListener implements Listener
    {
        @EventHandler
         public void onClick(PlayerInteractEvent e)
        {
            if(e.getAction()== Action.RIGHT_CLICK_AIR|| Action.RIGHT_CLICK_BLOCK==e.getAction())
            {
                if(e.getItem().getType()==Material.SLIME_BLOCK)
                {
                    e.setCancelled(true);
                    e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.JUMP,30*20,4));
                    e.getPlayer().getInventory().setItem(e.getPlayer().getInventory().getHeldItemSlot(), new ItemStack(Material.AIR));
                }
              }
            }
    }
     
  2. check if the item in hand isn't null
     
    • Agree Agree x 1
  3. Oh man,its to late for me ^^
     
    • Friendly Friendly x 1
  4. mark your thread solved please