Scoreboard sidebar - Displaying values.

Discussion in 'Spigot Plugin Development' started by Invaerne, Jun 2, 2018.

  1. Hi guys - What is the best way to store players' score? For example number of killed entities.

    What is the best way to display players' score as a listlis a scoreboard sidebar?
     
    #1 Invaerne, Jun 2, 2018
    Last edited: Jun 2, 2018
    • Useful Useful x 1
  2. Sorry, I explained the problem incorrectly. The actual problem is with displaying these values. I will provide the code later today.
     
  3. okay I'll have a look at it
     
  4. Sorry for a late response.

    Here is the code that I use to show all players the score of a single player and it works perfectly.

    Code (Text):
            private void scoreboard(Player p) {
                String name = p.getPlayer().getName();
                ScoreboardManager m = Bukkit.getScoreboardManager();
                Scoreboard b = m.getNewScoreboard();


                Integer scored = this.score.get(p.getName());
                Objective o = b.registerNewObjective(name, scored.toString());
                o.setDisplaySlot(DisplaySlot.SIDEBAR);
                o.setDisplayName("Test");

                Score gold = o.getScore(name);
                gold.setScore(scored);
                  for (Player pe : Bukkit.getOnlinePlayers()) {
                        pe.setScoreboard(b);
                       
                       
                  }
                     

                }


    However, I am struggling to display all the scores from the hashmap...

    Code (Text):
                String name = p.getPlayer().getName(); //should I use Player pe : Bukkit.getOnlinePlayers() instead?
                ScoreboardManager m = Bukkit.getScoreboardManager();
                Scoreboard b = m.getNewScoreboard();


                Integer scored = this.score.get(p.getName()); // should I use Player pe : Bukkit.getOnlinePlayers() instead?
                Objective o = b.registerNewObjective(name, scored.toString());