Scoreboard help

Discussion in 'Spigot Plugin Development' started by HazeDev, Nov 4, 2018.

  1. I've created a new Scoreboard, registered a new Objective and then created a Score.
    I've tried setting the score to 0 and negative values but i cannot find a way to remove the score.
    Is it possible to remove the score without unregistering the associated Objective?
     
  2. At the moment I intend to use one objective and register all 15 scores with that. And then when a value is changed, unset the previous score and make a new score.

    For example:
    Title
    Online Players: 16 15
    Online Staff: 3 14
    Balance: 15857463528 13
    Blocks Mined: 4758693 12

    I would like to unregister the score "Online Players: 16" and register a new one "Online Players: 15".

    If this is not possible the alternative would be to register a new Objective every time a value needs updating...
     
    #2 HazeDev, Nov 4, 2018
    Last edited: Nov 4, 2018
  3. You can try this:

    Code (Java):
    Scoreboard board = p.getScoreboard();

    if(board.getObjective("YourOBJName") != null) board.getObjective("YourOBJName").unregister();

    Objective obj = board.registerNewObjective("YourOBJName", "dummy");
    obj.getScore("Online Player " + playersOnline).setScore(13);
     
    You do not need to set the scoreboard again, because of the "Scoreboard board = p.getScoreboard();", but a unregister of the object is necessary.
     
  4. Okay thanks, I'll have to rethink some of my logic but this isn't too bad.
     
  5. Could you expand on the usage of Teams? This is what I've done to test and it does nothing...

    Code (Java):
    Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    Team team = scoreboard.registerNewTeam("TeamName");
    team.addEntry("addEntry()");
    team.setColor(ChatColor.GOLD);
    team.addEntry("addEntry()2");
    team.setPrefix("Prefix");
    team.setSuffix("Suffix");
    player.setScoreboard(scoreboard);
    EDIT: I'm not sure when Teams would be useful because I don't know what capabilities they grant. However, Scores will probably do what I want them to do because I found the method Scoreboard.resetScores(String entry) which is exactly what I was looking for when I created this Thread.
     
    #5 HazeDev, Nov 4, 2018
    Last edited: Nov 4, 2018
  6. You're creating the team but you're not adding the player to the team. I'm pretty sure you need to.
     
  7. Team.addPlayer(OfflinePlayer player) is deprecated