Solved Plugin need help

Discussion in 'Plugin Development' started by GreatMinerZ, May 12, 2013.

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

    GreatMinerZ

    Hey, i'm trying to make a simple plugin which makes it so if you hold a nether star, you will get super speed when you're sprinting.
    I already have this done:

    Code:
        @EventHandler
        public void onItemHeld(PlayerItemHeldEvent event){
            if (!(sender instanceof Player)) return;
            Player p = (Player) sender;
            if(p.getItemInHand().getTypeId() == 2261 ){
                p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200000, 25), false);
            }
        }
    But both of the sender's have a red line under it and what do i need to add to make it only give them the PotionEffect when they're sprinting?

    Thanks!
     
  2. Offline

    Stealth2800

    Sender isn't defined anywhere. Use event.getPlayer() to get the player the event is associated with. It's a player event, so do you don't have to check to make sure it's not the Console.

    Code:
    @EventHandler
    public void onItemHeld(PlayerItemHeldEvent event){\
      Player p = event.getPlayer();
        if(p.getItemInHand().getTypeId() == 2261 ){
          p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200000, 25), false);
        }
    }
    
     
    GreatMinerZ likes this.
  3. Offline

    Compressions

    GreatMinerZ Learn basic Java first before you make plugins.
     
  4. Offline

    GreatMinerZ

    Thanks, works now :)
     
Thread Status:
Not open for further replies.

Share This Page