Cannot get my timer for my mini-game to work

Discussion in 'Bukkit Help' started by LateNightLotion, Aug 11, 2014.

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

    LateNightLotion

    So here is my problem, I have a timer class that I am trying to make handle the countdowns and things like that, I am calling it in the onEnable but it only gets to a certain point and then stops running(It will say"I am sorry but the game requires "+Core.minPlayers+" to start!"). I am pretty familiar with java and bukkit so I will most likely know what you are talking about, the only thing is most of my plugins do not require timers. Here is my code

    Timer Class:

    public class timeManager implements Runnable
    {

    public final int lobbyTimer = 120;
    public final int warmupTimer = 60;

    @Override
    public void run()
    {
    //If the timer is larger than one
    if(Core.getTicks()>1)
    {
    Core.setTicks(Core.getTicks()-1);
    }

    //This is setting up the lobby timer
    if(Core.getState()==GameState.Lobby)
    {

    if(Core.getTicks()>0&&Core.getTicks()<=10||Core.getTicks()>0&&Core.getTicks()%30==0)
    {
    Bukkit.broadcastMessage(Core.TAG+"The game begins in "+Core.formatTime(Core.getTicks())+"...");

    for(Player pl:Bukkit.getOnlinePlayers())
    {
    pl.playSound(pl.getLocation(), Sound.CLICK, 100, 100);

    }
    }
    if(Core.getTicks()==0)
    {
    if(Bukkit.getOnlinePlayers().length>=Core.minPlayers)
    {
    //TODO start the game in warmup, loop through the online players and then set the paper to a new gamestate
    //add the warmup timer
    }
    else
    {
    Core.setTicks(lobbyTimer);
    Bukkit.broadcastMessage(Core.TAG+"I am sorry but the game requires "+Core.minPlayers+" to start!");
    Core.setTicks(lobbyTimer);
    for(Player pl: Bukkit.getOnlinePlayers())
    {
    pl.playSound(pl.getLocation(), Sound.CLICK, 100, 100);
    }
    }
    }
    }

    Main Class:

    public class Core extends JavaPlugin
    {
    @Override
    public void onEnable()
    {

    //Trying to run the timer

    getServer().getScheduler().runTask(this, new timeManager());


    }

    public static int ticks = 0;

    public static void setTicks(int ticks)
    {
    Core.ticks=ticks;
    }

    public static int getTicks()
    {
    return Core.ticks;
    }

    public static GameState state;

    public static void setState(GameState state)
    {
    Core.state= state;
    }

    public static GameState getState()
    {
    return Core.state;
    }
    }

    Sorry for the code mess, I do not know how to format the code like the other people who post but I really need help with this!
     
Thread Status:
Not open for further replies.

Share This Page