Scoreboard update score problem

Discussion in 'BungeeCord Plugin Development' started by Aurorion, Jul 6, 2015.

  1. Hi!
    So this basicly is a easy problem to understand but after I got confused I couldn't see things clear anymore.
    The problem is that I have a scoreboard that shows kills. Kill get stored into a file so to get the amount of kills I use this code for the score:
    Code (Text):
    Score kills         = redboardobj.getScore("§eKills: §f" + aurosettings.getEdata().getInt("Spelers." + player.getUniqueId() + ".kills"));
    But whenever someone kills a player and there for gets +1 kill and i update the scoreboard I get this little problem: http://i.gyazo.com/9889d3e515800e4bba409bee3b9296c2.png
    And that goes on every time some one gets +1 kill.

    Any got an idea to only update the amount of kills shown?

    Thanks in advance!
     
  2. Reset the score is the magic trick
     
  3. That's what I use when I add/update a score:
    Code (Text):
    private void addScore(String string, byte count, String id) {
            for (String entry : bukkitScoreboard.getEntries()) {
                if (entry.contains(id)) {
                    if (!entry.equals(string)) {
                        // clear old information
                        bukkitScoreboard.resetScores(entry);
                        // update information
                        bukkitObjective.getScore(string).setScore(count);
                    }
                    return;
                }
            }
            // add new information
            bukkitObjective.getScore(string).setScore(count);
        }
    string is the name of the score, count is the count at the right and id is something that's in the string in every case.
    That code just checks if a similar string with the same id already exists and then just removes the old one if required and adds the new one.
    bukkitObjective is your objective of the scoreboard, don't create a new scoreboard/objective for each change.
    bukkitScoreboard is obviously the scoreboard.

    Edit: Also next time if you post something in the wrong section, please just report it saying you want to get it moved instead of creating a new thread.