Problem with Scheduler outside a class

Discussion in 'Spigot Plugin Development' started by Devin_54321, May 14, 2016.

  1. So I am working on a multi arena plugin, and I'm trying to create a scheduler that can run all the games at once, in one class. I have an idea of what it should do, but I can't get it right. Here is what I have so far:
    Code (Java):

    package me.DevOG;

    import java.util.ArrayList;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Server;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scheduler.BukkitScheduler;
    import tfw.CAC.ArenaManagement.Arena;
    import tfw.CAC.ConfigManagement.Messages;
    import tfw.CAC.ConfigManagement.Settings;
    import tfw.CAC.GameManagement.GameStage;
    import tfw.CAC.GameManagement.State;

    public class SimplyCountdown
    {
      private final Plugin plugin;
      private int countdownTimer;
      private Arena arena;
      private static int timeOnClock;
      public SimplyCountdown(Plugin plugin2, Arena a)
      {
        this.plugin = plugin2;
        this.arena = a;
      }
      public int timeLeft()
      {
        return timeOnClock;
      }
      public void startCountdown(int time)
      {
        timeOnClock = time;
        if (this.arena.getStage() == GameStage.BETWEEN_ROUNDS) {
          this.arena.updateBoard();
        }
        if (this.arena.getStage() == GameStage.INGAME) {
          this.arena.updateBoard();
        }
        this.countdownTimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable()
        {
          int i;
       
          public void run()
          {
            for (UUID u : SimplyCountdown.this.arena.getPlayers())
            {
              Player p = Bukkit.getServer().getPlayer(u);
              p.setLevel(this.i);
              if (SimplyCountdown.this.arena.getState() == State.PLANTED) {
                p.playSound(p.getLocation(), Sound.CLICK, 1.0F, 0.0F);
              }
            }
            if (SimplyCountdown.this.arena.getStage() == GameStage.BETWEEN_ROUNDS) {
              SimplyCountdown.this.arena.updateBoard();
            }
            if (SimplyCountdown.this.arena.getStage() == GameStage.INGAME) {
              SimplyCountdown.this.arena.updateBoard();
            }
            if (this.i <= 0)
            {
              if (SimplyCountdown.this.arena.getStage() == GameStage.INGAME)
              {
                if (SimplyCountdown.this.arena.getState() == State.DEFAULT)
                {
                  SimplyCountdown.this.arena.endRound(SimplyCountdown.this.arena.getCops(), Messages.getAny("COPS"));
                }
                else
                {
                  if (SimplyCountdown.this.arena.getChest() != null) {
                    SimplyCountdown.this.arena.getChest().getLocation().getWorld().createExplosion(SimplyCountdown.this.arena.getChest().getLocation(), 0.0F);
                  }
                  for (Player p : Bukkit.getOnlinePlayers()) {
                    p.playSound(p.getLocation(), Sound.EXPLODE, 1.0F, 0.0F);
                  }
                  SimplyCountdown.this.arena.endRound(SimplyCountdown.this.arena.getCrims(), Messages.getAny("CRIMINALS"));
                }
              }
              else if (SimplyCountdown.this.arena.getStage() == GameStage.BETWEEN_ROUNDS) {
                SimplyCountdown.this.arena.startRound();
              } else if (SimplyCountdown.this.arena.getStage() == GameStage.STARTING) {
                if (SimplyCountdown.this.arena.getPlayers().size() >= Settings.minPlayers())
                {
                  SimplyCountdown.this.arena.preGame();
                }
                else
                {
                  SimplyCountdown.this.arena.setStage(GameStage.LOBBY);
                  SimplyCountdown.this.arena.broadcastMessage(Messages.getPrefix() + Messages.getAny("INSUFFICIENT_PLAYERS"));
                }
              }
              SimplyCountdown.this.cancel();
            }
            this.i -= 1;
            SimplyCountdown.timeOnClock -= 1;
          }
        }, 0L, 20L);
      }
      public void cancel()
      {
        Bukkit.getScheduler().cancelTask(this.countdownTimer);
      }
    }
     
     
  2. What are your errors?
     
  3. None, it just doesn't work
     
  4. Put in debug messages so you know what's going wrong.