Get highest score from scoreboard

Discussion in 'Plugin Development' started by slater96, Aug 17, 2013.

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

    slater96

    Hello, I'm trying to get the player with the highest score(kills) from the scoreboard, here's my code.

    Code:
                            ScoreboardManager manager = Bukkit.getScoreboardManager();
                            Scoreboard board = manager.getNewScoreboard();
                            Objective objective = board.registerNewObjective("Kills", "dummy");
                            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                            objective.setDisplayName(ChatColor.RED + "Kills");
                            Set<String> playing = plugin.getConfig().getConfigurationSection("Arenas." + arena + ".Playing").getKeys(false);
                            for (String inGame : playing) {
                                Score score = objective.getScore(Bukkit.getPlayer(inGame));
                                score.setScore(plugin.playerKills.get(Bukkit.getPlayer(inGame).getName()));
                                Bukkit.getPlayer(inGame).setScoreboard(board);
                            }
     
    etaxi341 likes this.
  2. Offline

    Staartvin

    You would get a list of the scores, then loop through them and save the highest value along with the player that has that score.
     
  3. Offline

    etaxi341

    Staartvin Yes I thought about something like this too... But I am not sure if this is Super-efficient. I think there are better ways so I didn't wrote this. But yes you are right. This is a way.
     
  4. Offline

    Staartvin

    etaxi341

    I'm sure there is a more efficient way, but I'm afraid I don't know.
     
  5. Offline

    slater96

  6. Offline

    Staartvin

    slater96

    I haven't figured out how to work with the Scoreboard API yet, but it is sort of working with a list of values.
     
Thread Status:
Not open for further replies.

Share This Page