Bukkit Runnable doesn't run

Discussion in 'Spigot Plugin Development' started by tatemylove, Apr 17, 2017.

  1. Code (Text):

        public static void checkPlayerCount()
        {
            if ((Main.WaitingPlayers.size() >= Main.minplayers) && (BaseArena.States == BaseArena.states.WAITING))
            {
                BaseArena.States = BaseArena.states.COUNTDOWN;
                startLobbyCountdown();
                return;
            }
            if ((Main.WaitingPlayers.size() >= Main.minplayers) && (BaseArena.States == BaseArena.states.COUNTDOWN)) {
                return;
            }
            if ((Main.WaitingPlayers.size() < Main.minplayers) && (BaseArena.States == BaseArena.states.COUNTDOWN)) {
                BaseArena.States = BaseArena.states.WAITING;
            }
        }

        public static void startLobbyCountdown()
        {

            if (Main.WaitingPlayers.size() < Main.minplayers) {
                return;
            }
            if (BaseArena.States != BaseArena.states.WAITING) {
                return;
            }
            final ArrayList<String> arena = new ArrayList();
            BukkitRunnable br = new BukkitRunnable()
            {
                int time;
                public void run()
                {

                    for (Player pp : Main.WaitingPlayers) {
                        pp.setLevel(time-1);
                    }
                    if (BaseArena.States != BaseArena.states.COUNTDOWN) {
                        cancel();
                    }
                    time -= 1;
                    if (time == 60-1)
                    {
                        for (Player pp : Main.WaitingPlayers)
                        {
                            pp.sendMessage(Main.msprefix + "§9§l60 Seconds Left!");
                            pp.sendMessage(Main.msprefix + "Next Arena: " + (String)arena.get(0));
                        }
                    }
                    else if (time == 30-1)
                    {
                        for (Player pp : Main.WaitingPlayers)
                        {
                            pp.sendMessage(Main.msprefix + "§9§l30 Seconds Left!");
                            pp.sendMessage(Main.msprefix + "Next Arena: " + (String)arena.get(0));
                        }
                    }
                    else if (time == 15-1)
                    {
                        for (Player pp : Main.WaitingPlayers)
                        {
                            pp.sendMessage(Main.msprefix + "§9§l15 Seconds Left!");
                            pp.sendMessage(Main.msprefix + "Next Arena: " + (String)arena.get(0));
                        }
                    }
                    else if (time == 10-1)
                    {
                        for (Player pp : Main.WaitingPlayers)
                        {
                            pp.sendMessage(Main.msprefix + "§9§l10 Seconds Left!");
                            pp.sendMessage(Main.msprefix + "Next Arena: " + (String)arena.get(0));
                        }
                    }
                    else if (time == 5-1)
                    {
                        for (Player pp : Main.WaitingPlayers)
                        {
                            pp.sendMessage(Main.msprefix + "§9§l5 Seconds Left!");
                            pp.sendMessage(Main.msprefix + "Next Arena: " + (String)arena.get(0));
                        }
                    }
                    else if (time == 0-1)
                    {
                        BBDArena.assignTeam(Integer.toString(getArena.getCurrentArena()));
                        BBDArena.start(Integer.toString(getArena.getCurrentArena()));
                        GameCountDown.startGameCountdown();
                    }
                    else if (time < 0)
                    {
                        BaseArena.States = BaseArena.states.STARTED;
                        cancel();
                        arena.clear();
                    }
                }
            };
           br.runTaskTimerAsynchronously(ThisPlugin.getPlugin(), 0L, 20L);
        }
    Spent an hour trying to figure out why the runnable wasn't running on the test server. I set my min players to 1, so when I joined it would run the runnable and when I joined the WaitingPlayer ArrayList by typing /bbd join, I also put checkPlayerCount(), into my join command. Lastly, I added BaseArena.States = BaseArena.states.WAITING; into the onEnable(){}.
     
  2. First you set the state to COUNTDOWN, then you call startLobbyCountdown. Within that method you check if the state is anything other than WAITING, which, logically, will always be the case. And then you return from the method, before the task got scheduled.
     
  3. Alright thanks man.