[1.8.9] Scoreboard displaying 0 instead of value.

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

  1. Hey everyone!
    Looked around at tutorials and the methods used in tutorials have since been depreciated.
    Also this part of the spigot api always seems to look awful/messy/lacking explination when used in an example.

    So I have:

    Code (Text):
    scoreboard= Bukkit.getServer().getScoreboardManager().getNewScoreboard();
            objective = scoreboard.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
            objective.setDisplayName("Level");
            score = objective.getScore("test");
            score.setScore(5);
            System.out.println(score.getScore());
            p.setScoreboard(scoreboard);
     
    which displays "0 Level" Under the players name even though the output from the println is 5.
    I get that somehow my score setting is wrong but I have no idea how.

    Any help appreciated.
     
  2. are you trying to get the player health?
     
  3. You set the score for a player with the name "test", do this instead.
    Code (Text):
    score = objective.getScore(p);
     
  4. I am not :s
    See the method getScore(Offline/Player) is depreciated and the annotation on the other method was a String saying
    "Gets an entry's Score for an Objective on this Scoreboard."
    Which I fail to see how i'm supposed to derive entity name from, but all is well if it works.
     
  5. @Darkened_Soul everyone online needs that same scoreboard, or every player will see the other players have a score of 0
     
  6. I do not which to be a pain but may you elborate.
    In the examples i've seen they were only ever allocated to the person to be displayed on, and since everyone can only have 1 scoreboard
    how would that work.
     
  7. @Darkened_Soul not everyone's examples are perfect, and you could have also misinterpreted it. For each #getNewScoreboard(), you create a whole new scoreboard with unique scores. If you assign it to 1 player, they will see all other players' scores different than they do. You need to save a Scoreboard in, for example, your onEnable, and assign it to everyone who joins
     
  8. To clarify quickly.
    Create 1 score board on enable.
    On Join create 1 Score per person.
    Allocate the 1 Scoreboard containing all the individual scores to each player.
     
  9. It is depreciated because you shouldn't do it with an OfflinePlayer, however Player should be safe. Otherwise just use the name of the player, not "test".
     
  10. Thank-you very much, I'll give this a go and see how bald I go before I manage to get it right.