Problem/Bug Why is my Plugin Message Spamming?

Discussion in 'Plugin Help/Development/Requests' started by TECGaming360, Jun 26, 2015.

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

    TECGaming360

    So I have a Plugin that turns off a players flight when Person leaves but right when a person leaves it puts out the message in the Yaml defined as flyZoneExitMessage

    It repeats and repeats and repeats! The messages don't stop until you leave the Game or Go back to fly zone.

    Below is a copy of the java file were the message is only displayed:


    Code:
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    //Java plugin Crafted by Ryan Tarson, TECGaming
    
    public class PluginLoop {
    
        public int taskID;
        public int taskIDPayment = 0;
       
        public void startLoop()
        {
            this.taskID = FlyZones.self.getServer().getScheduler().scheduleSyncRepeatingTask(FlyZones.self, new Runnable(){
                @Override
                public void run()
                {
                    for(Player p : Bukkit.getOnlinePlayers())
                    {
                        if(p.isDead())
                        {
                            if(FlyZones.self.playerZoneMap.containsKey(p))
                            {
                                FlyZones.self.playerZoneMap.remove(p);
                            }
                            if(FlyZones.self.playerGraceTimer.containsKey(p))
                            {
                                FlyZones.self.playerGraceTimer.remove(p);
                            }
                            continue;
                        }
                        if(!p.hasPermission("flyzones.ignore"))
                        {
                            Location loc = p.getLocation();
                            World world = loc.getWorld();
                            ArrayList<FlyZone> list = FlyZones.self.flyZoneMap.get(world);
                           
                            if(list != null)
                            {
                                boolean isWithin = false;
                                for(FlyZone zone : list)
                                {
                                    if(zone.isWithin(loc) ||  )
                                    {
                                        if(!FlyZones.self.playerZoneMap.containsKey(p))
                                        {
                                            p.sendMessage(FlyZones.self.flyZoneEnterMessage);
                                            FlyZones.self.playerZoneMap.put(p, zone);
                                            if(FlyZones.self.playerGraceTimer.containsKey(p))
                                                FlyZones.self.playerGraceTimer.remove(p);
                                        }
                                        isWithin = true;
                                        break;
                                    }
                                }
                                if(!isWithin)
                                {
                                    if(FlyZones.self.playerZoneMap.containsKey(p))
                                    {
                                        p.sendMessage(FlyZones.self.flyZoneExitMessage);
                                        FlyZones.self.playerZoneMap.remove(p);
                                        FlyZones.self.playerGraceTimer.put(p, 0);
                                    }
                                    else
                                    {
                                        if(FlyZones.self.playerGraceTimer.containsKey(p))
                                        {
                                            int timer = FlyZones.self.playerGraceTimer.get(p);
                                            timer += 5;
                                            if(timer >= FlyZones.self.flyZoneExitGracePeriod*20)
                                            {
                                                p.sendMessage(FlyZones.self.flyZoneGracePeriodEndedMessage);
                                                p.setFlying(false);
                                                if(FlyZones.self.essentials != null)
                                                {
                                                    FlyZones.self.essentials.getUser(p).setAllowFlight(false);
                                                }
                                                FlyZones.self.playerGraceTimer.remove(p);
                                            }
                                            else
                                                FlyZones.self.playerGraceTimer.put(p, timer);
                                        }
                                        else
                                        {
                                            if(p.isFlying())
                                            {
                                                p.setFlying(false);
                                            }
                                            if(FlyZones.self.essentials != null)
                                            {
                                                if(FlyZones.self.essentials.getUser(p).getAllowFlight())
                                                    FlyZones.self.essentials.getUser(p).setAllowFlight(false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }, 0, 5); //20 ticks = 1 second
           
        }
    
        public void endLoop()
        {
            FlyZones.self.getServer().getScheduler().cancelTask(this.taskID);
        }
    
    }
    

    Also quick question would i detect if a person flightmode is enabled?
     
  2. Offline

    TECGaming360

Thread Status:
Not open for further replies.

Share This Page