Need help "cannot be resolved"

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

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

    GreatMinerZ

    Hey,

    I'm new to bukkit and trying to create some easy plugins.
    With this one i'm trying to give a player unlimited speed when the player is holding a Red dye.
    But when i'm trying to do this i get the following error:

    Code:
            Player p = (Player) sender;
     
        if(player.getItemInHand().getTypeId() == 351 &&
                player.getItemInHand().getData().getData() == 1)
            {
            p.addPotionEffect(
                      new PotionEffect(PotionEffectType.SPEED, 200000, 25), false);
            }
    sender and player cannot be resolved. Anyone know how to fix this?

    Thanks!
     
  2. Offline

    TnT

    Moved to the correct forum.
     
  3. Offline

    CubieX

    Your player object is "p" and not "player". So please use "p" in your "if"-statement. That's one of the errors.

    Where is this piece of code located? In the onCommand method or an EventHandler?
    Seems like "sender" is not properly initialized.
     
  4. Offline

    RROD

    In response to CubieX, this is what you will need to do.

    Code:java
    1.  
    2. if (!(sender instanceof Player)) return;
    3. Player p = (Player) sender;
    4.  
    5. if(p.getItemInHand().getTypeId() == 351 && player.getItemInHand().getData().getData() == 1) {
    6. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200000, 25), false);
    7. }
    8.  
     
  5. Offline

    GreatMinerZ

    Thanks, but what do i need to type above the code? :confused:

    I already have onEnable and onDisable
     
Thread Status:
Not open for further replies.

Share This Page