Solved Can't check if item == Material.STICK

Discussion in 'Plugin Development' started by realmdude, Dec 30, 2020.

  1. Offline

    realmdude

    I am trying to create a wand that creates an explosion where you look.

    Here is my code:
    @EventHandler@Deprecated
    public void onInteract(PlayerInteractEvent e) {
    Action action = e.getAction();{
    if (action == Action.RIGHT_CLICK_AIR)
    Player p = e.getPlayer();ItemStack item = p.getInventory().getItemInHand(); if == Material.STICK else throw return;
    p.getWorld().createExplosion(p.getLocation(), 3.0f);}
    }
    }

    I'm still new to this, how can I check if it's a stick then run the explosion on a right click? I only want it to explode if they're holding a stick (preferably the wand). Thanks!
     
  2. Offline

    Newdel

    What did you want to do?
     
  3. Offline

    realmdude

    I was trying to check if it was a stick, and if it wasn't, then return the code (which is supposed to rerun it, right?)
     
  4. Online

    timtower Administrator Administrator Moderator

    Nope, does not rerun the code.
    if(item.getType()==Material.STICK)
     
  5. Offline

    realmdude

    I got it to work, thanks!
     

Share This Page