Solved Scoreboard not the same as everyone else

Discussion in 'Plugin Development' started by voltywolty, Oct 23, 2021.

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

    voltywolty

    Hey everyone. I'm currently making a scoreboard system that everyone should see the same values of, but for some reason the values aren't the same across ALL players. On my client it says Remaining: 1, but then on my second client it says, Remaining: 2. Is there something im doing wrong? Here are my scoreboard methods.

    Code:
    public void initializeScoreboard(Player player) {
            this.manager = Bukkit.getScoreboardManager();
            this.scoreboard = manager.getNewScoreboard();
            this.objective = this.scoreboard.getObjective("Dwarves");
    
            if (this.objective == null) {
                this.objective = this.scoreboard.registerNewObjective("Dwarves", "dummy", ChatColor.AQUA + "Dwarves");
                this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            }
    
            this.remainingDwarvesScore = this.objective.getScore(ChatColor.GREEN + "Remaining");
            this.remainingDwarvesScore.setScore(dwarves.size());
            this.monsterKillsScore = this.objective.getScore(ChatColor.RED + "Kills");
            this.monsterKillsScore.setScore(monsterKills);
    
            player.setScoreboard(scoreboard);
        }
    
        public void updateScoreboards() {
            for (Player online : Bukkit.getOnlinePlayers()) {
                this.remainingDwarvesScore = this.objective.getScore(ChatColor.GREEN + "Remaining");
                this.remainingDwarvesScore.setScore(dwarves.size());
                this.monsterKillsScore = this.objective.getScore(ChatColor.RED + "Kills");
                this.monsterKillsScore.setScore(monsterKills);
            }
        }
    
        public void updateScoreboard() {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
                public void run() {
                    DvZ.this.updateScoreboards();
                }
            }, 0L, 100L);
        }
     
  2. Offline

    Kars

    You are making a new scoreboard for every player and overwriting this.scoreboard with it. With your code you can only ever update the lastly initialized scoreboard.
    To achieve what you want you need to initialize the scoreboard once and set that scoreboard for all players.
     
  3. Offline

    voltywolty

    I see what I did... I did getNewScoreboard rather than getMainScoreboard
     
Thread Status:
Not open for further replies.

Share This Page