Solved Scoreboard scores are duplicating

Discussion in 'Plugin Development' started by T0pAz7, Jan 12, 2015.

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

    T0pAz7

    I have this problem where my scores on the scoreboard get's duplicated every time it updates to a new value. I think I know the problem since the string is different, it creates a new score every time. But, cannot seem to put my head around in fixing it. Any help?

    Code:
    public static void CreateClanboard()
            {
            ClanBoard = Bukkit.getScoreboardManager().getNewScoreboard();
            ObjStats = ClanBoard.registerNewObjective("Stats", "dummy");
            ObjStats.setDisplaySlot(DisplaySlot.SIDEBAR);
            ObjStats.setDisplayName("Stats: ");
        }
    
        public static void UpdateClanboard()
        {
            Collection< ? extends Player> players = Bukkit.getOnlinePlayers();
            PlayerData playerData;
            ClanData clanData;
            Score clanname;
            Score clanpoints;
            Score coins;
            Score skillpoints;
    
            for(Player player : players)
            {
                if(player != null && player.isOnline())
                {
                    playerData = PlayerManager.GetPlayerData(player);
                    clanData = ClanManager.GetClan(playerData.Clan);
    
                    if(clanData == null)
                    {
                        coins = ObjStats.getScore(ChatColor.AQUA + "Coins: " + ChatColor.GOLD + PlayerManager.GetPlayerCoins(player));
                        coins.setScore(7);
                        skillpoints = ObjStats.getScore(ChatColor.AQUA + "Skill Points: " + ChatColor.GOLD + playerData.SkillPoints);
                        skillpoints.setScore(6);
                        player.setScoreboard(ClanBoard);
    
    
                    }
                    else
                    {
                        clanname = ObjStats.getScore(ChatColor.AQUA + "Clan Name: " + ChatColor.GOLD + playerData.Clan);
                        clanname.setScore(9);
                        clanpoints = ObjStats.getScore(ChatColor.AQUA + "Clan Points: " + ChatColor.GOLD + clanData.Points);
                        clanpoints.setScore(8);
                        coins = ObjStats.getScore(ChatColor.AQUA + "Coins: " + ChatColor.GOLD + GetPlayerCoins(player));
                        coins.setScore(7);
                        skillpoints = ObjStats.getScore(ChatColor.AQUA + "Skill Points: " + ChatColor.GOLD + playerData.SkillPoints);
                        skillpoints.setScore(6);
                        player.setScoreboard(ClanBoard);
                    }
    
    
                    player.setHealth(player.getHealth());
                }
            }
        }
    Code:
    @Override
        public void onEnable()
        {
            ...
            PlayerManager.CreateClanboard();
            getServer().getScheduler().scheduleSyncRepeatingTask(this, ClanboardUpdate(), 30L, 30L);
           ...
        }
    
        private Runnable ClanboardUpdate()
        {
            return new Runnable()
            {
                @Override
                public void run()
                {
                    PlayerManager.UpdateClanboard();
                }
            };
        }
     
  2. Offline

    QuipCream

    Does it duplicate if any value is changed or is it a specific value?
     
  3. Offline

    T0pAz7

    Only if value is changed.
     
  4. Offline

    unrealdesign

    1. player.setHealth(player.getHealth()) is useless unless you have some reason for a weird work around
    2. None of this code shows where you're setting the scoreboard to the player. I'm guessing you're creating a new scoreboard every time you update the scoreboard and it's creating a new one every time.
     
  5. Offline

    T0pAz7

    I am setting the scoreboard to the player every 30 ticks including the objectives. But I am not creating new scoreboard.
     
  6. Offline

    unrealdesign

    @T0pAz7 The only way you can have this error that I know of with the limited knowledge of the Scoreboard API is that you're chaning the value of variable "ClanBoard" somewhere else in your code.
     
  7. Offline

    T0pAz7

    Those are the only places I have used it. Seems like a 1.8 issue.
     
  8. Offline

    unrealdesign

    Maybe, but what I'm saying is, you might be calling CreateClanboard() multiple times which is overwriting the old board. You didn't post everything, so I have no idea.
     
  9. Offline

    T0pAz7

    Well that's everything that has to do with the scoreboard.
     
  10. Offline

    teej107

  11. Offline

    T0pAz7

  12. Offline

    teej107

    @T0pAz7 Have you checked the Bukkit documentation?
     
  13. Offline

    T0pAz7

    Thanks, I got it by doing this before setting the scores.

    Code:
    Set<String> entries;
    
            entries = ClanBoard.getEntries();
    
            for(String entry : entries)
            {
                ClanBoard.resetScores(entry);
            }
     
Thread Status:
Not open for further replies.

Share This Page