Solved Changing variable in scheduleSyncRepeatingTask

Discussion in 'Plugin Development' started by MGlolenstine, May 28, 2017.

Thread Status:
Not open for further replies.
  1. How would I change a variable in scheduleSyncRepeatingTask?
    my current code:
    Code:
    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
                        public void run(){
                            int players = plugin.getConfig().getInt(w.getName()+".players.players_online");
                            int possible = plugin.getConfig().getInt(w.getName()+".players.number_of_players");
                            lines[2] = players+"/"+n*possible;
                            if(players >= possible/2){
                                lines[3] = ChatColor.GREEN+"Ready to start!";
                            }else if(players < possible/2){
                                lines[3] = ChatColor.GOLD+"Getting ready";
                            }else{
                                lines[3] = ChatColor.RED+"Server is offline!";
                            }
                            s.update();
                        }
                    },0, 20);
    I'd need to change "players" variable
     
  2. Offline

    Zombie_Striker

    @MGlolenstine
    If you mean change it from outside of the task, then the only way would be to change the int in the config.
     
  3. Well... I meant changing in the task, that is in the runtime of the task. The value in the config is changing from 0-16, but it's always showing 1 as it was when this task was run.

    If I understand this repeatable task syntax, I run this one every second? And then it should be changing the variable players to the value in the config... Am I right? Why isn't it changing it's variable while running?

    It's kinda like InfiniteLoop but it's running every second... Am I right? @Zombie_Striker
     
  4. Offline

    Zombie_Striker

    @MGlolenstine
    You would need to reload the config if you made any changes to it. Try adding plugin.reloadConfig() before getting the int.
     
  5. Thank you! Exactly what I wanted!
     
  6. Offline

    Zombie_Striker

    @MGlolenstine
    If your problem has been solved, mark this thread as solved.
     
    MGlolenstine likes this.
Thread Status:
Not open for further replies.

Share This Page