Solved Code is not working

Discussion in 'Plugin Development' started by DeudlyYT, Sep 7, 2015.

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

    DeudlyYT

    Hi, I want to do a plugin which when you leash an animal you have a superpower. And my code dont work

    Code:
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.event.Listener;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerLeashEntityEvent;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Chicken;
    import org.bukkit.entity.Squid;
    
    public class Parachute extends JavaPlugin implements Listener {
      
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
          
        }
    
        @EventHandler
        public void onLeash(PlayerLeashEntityEvent LeashEvent){
          
            Player player = LeashEvent.getPlayer();
            Entity leashed = LeashEvent.getEntity();
            getLogger().info(LeashEvent.getPlayer().getName() + " leashed!");
          
            if (leashed instanceof Chicken){
                player.sendMessage("I'm a chicken bro");
                player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 30, 30));
                      
            if (leashed instanceof Squid) {
                player.sendMessage("I'm a squid bro");
                player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 30, 30));
              
                    }
                }  
            }  
        }

    Pls help me.
     
    Last edited: Sep 7, 2015
  2. Offline

    mine-care

    What do you mean it doesnt work? Does it show any error? does it compile? have you debuged? if yes, do the debug messages apear?
     
  3. Offline

    DeudlyYT

    Ok, so the server read the plugin perfectly and the messages appears ingame but the potion effect dosnt work
     
  4. Offline

    mine-care

  5. Offline

    TomeDM

    20 ticks = 1 second
     
  6. Offline

    DeudlyYT

  7. Offline

    mine-care

    @DeudlyYT No problem :) anytime!

    @TomeDM
    1.5 = 30
    1 = X => X= 20
    :p
    Anyway, good you said it, you saved the op some time
     
  8. Offline

    DeudlyYT

    Another problem, if I want to clear the potion effects when they unleash the animal. How Can I do that?
    I put this code and doesnt work.
    Code:
            public void onUnleash(PlayerUnleashEntityEvent Unleash){
                Player player = Unleash.getPlayer();
                Entity Unleashed = Unleash.getEntity();
                player.removePotionEffect(PotionEffectType.WEAKNESS);
                player.removePotionEffect(PotionEffectType.REGENERATION);
                player.removePotionEffect(PotionEffectType.ABSORPTION);
                player.removePotionEffect(PotionEffectType.HEAL);
                player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
                player.removePotionEffect(PotionEffectType.JUMP);
                player.removePotionEffect(PotionEffectType.SLOW);
                player.removePotionEffect(PotionEffectType.NIGHT_VISION);
               
            }
     
  9. Offline

    SuperSniper

    @DeudlyYT Did you put @EventHandler above the
    Code:
    public void onUnleash(PlayerUnleashEntityEvent Unleash){
    
    ?
     
    DeudlyYT likes this.
  10. Offline

    mine-care

  11. Offline

    DeudlyYT

    WoW, so much thanks. I didnt write @Override, Im learning Java and im creating my first plugin, but i have a lot of error. Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page