Why does an effect not repeat on a while loop?

Discussion in 'Plugin Development' started by LeGhost, Jul 24, 2015.

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

    LeGhost

    I have a plugin I am creating where if a player is flying, then they will have a weakness effect the is updated every 7 seconds, but for some reason, it doesn't update!!
    If anyone else knows if I am doing something wrong, please tell me. Also, if I can do this in a different way, please tell me. Thank You!!


    package me.LeGhost.main;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerToggleFlightEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class FlightAttempt implements Listener{
    @EventHandler
    public void onFlightAttempt(PlayerToggleFlightEvent event) {
    if(event.isFlying()) {
    if(event.getPlayer().isOp() || event.getPlayer().hasPermission("factionflight.fly")) {
    while(event.isFlying() && !event.getPlayer().hasPotionEffect(PotionEffectType.WEAKNESS)) {
    event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 140, 100));
    }
    }
    }

    }

    }
     
  2. Offline

    Nic2555

    I think you should check for the player to fly, not the event. Cast your event object or target to a player and then check if the player is flying.
     
  3. Offline

    LeGhost

    how do i do dis?
     
  4. Offline

    Nic2555

    You can use
    Code:
     
    Player p = event.getPlayer();
    If(p.isFlying())
    {
         while(p.isFlying() && 
    !event.getPlayer().hasPotionEffect(PotionEffectType.WEAKNESS)) {
              p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 140, 100));
         }
    
    }
    P.s. synthax might be wrong, I wrote this on a tablet.
     
  5. Offline

    1Rogue

    schedule this in a task, you're blocking the return of your method and causing the event firing to never complete.
     
Thread Status:
Not open for further replies.

Share This Page