Scoreboard Updater not working

Discussion in 'Spigot Plugin Development' started by KingDotCom, May 22, 2016.

  1. My scoreboard plugin won't update can someone help?

    Code (Text):
    package me.aaron.dev;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin implements Listener {
       
        static Plugin plugin;
       
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
        }
       

           

        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");
       
        int ops; {
        ops = 0;
        for(Player y : Bukkit.getOnlinePlayers()) {
            if(y.isOp()) {
                ops++;
            }
        }
           
        }
       
        int donors; {
            donors = 0;
            for(Player u : Bukkit.getOnlinePlayers()) {
                if(u.isOp()) {
                    donors++;
                }
            }
        }

       
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {

           
            final Player p = e.getPlayer();

           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
                public void run() {
                   
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                   
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&e» &4&lProsperity UHC &e«"));

                    Score score1 = objective.getScore(ChatColor.BOLD + "");
                    score1.setScore(15);
                    Score score2 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&2&lYou"));
                    score2.setScore(14);
                    Score score3 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&a" + p.getName()));
                    score3.setScore(13);
                    Score score4 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&1"));
                    score4.setScore(12);
                    Score score5 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&6&lPlayers"));
                    score5.setScore(11);
                    Score score6 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&e" + Bukkit.getServer().getOnlinePlayers().size()));
                    score6.setScore(10);
                    Score score7 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&3"));
                    score7.setScore(9);
                    Score score8 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&5&lStaff"));
                    score8.setScore(8);
                    Score score9 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&d" + ops));
                    score9.setScore(7);
                    Score score10 = objective.getScore("");
                    score10.setScore(6);
                    Score score11 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&1&lDonors"));
                    score11.setScore(5);
                    Score score12 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&b" + donors));
                    score12.setScore(4);
                    Score score13 = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&8"));
                    score13.setScore(3);
                   
                    p.setScoreboard(board);

                }
            },0, 20 * 3);
           
        }

    }
     
  2. Code (Text):
                   ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
    Declare them outside of the schedular.
     
  3. You should use teams insead of resetting the whole scoreboard.
     
  4. Teams are annoying af, although I want to know how to do it xD
     
  5. How are they anoying? They are alot better than using Score. Using teams you have no flicker (If you do it right).

    And if you want to know how to do just skyp me. I know you have my skype.
     
  6. idfk how to do it, do you?
    if you do, tell me ;3
     
  7. Yeah I do, I use them all the time. Hit me up with a pm. You seem to ignore me on skype xD
     
  8. remove the repeating task from the scoreboard and make in onEnable a repeating task and check for online players then set the scoreboard to the players who are online and set it with 20/40 L