Solved How to set Score as a double?

Discussion in 'Spigot Plugin Development' started by thanhdung756, Jul 14, 2018.

Thread Status:
Not open for further replies.
  1. Code (Text):
    private    void registerScoreboard() {

           if(board.getObjective("KothScoreboard") != null) {
              board.getObjective("KothScoreboard").unregister();
           }
         
            Objective objective = board.registerNewObjective("KothScoreboard", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(ChatColor.GOLD + "Koth Scores");

            ArrayList<Double> values = new ArrayList<>();
            values.addAll(timeInKoth.values());
            Collections.sort(values);
         
            ArrayList<Double> order = new ArrayList<>();
         
            for(int i = values.size()-1; i != -1; i--)
                order.add(values.get(i));
         
            for(Double i : order) {
                int x = 0;
                for (Entry<String, Double> e : timeInKoth.entrySet()) {
                    if(x <= 5) {
                       String key = e.getKey();
                       Double value = e.getValue();
                     
                       if(value == i) {
                            Score score = objective.getScore(ChatColor.GREEN + key + ": ");
                            score.setScore((int) Math.round(timeInKoth.get(key)));
                       }
                    }
                   x++;
                }
            }
         
            for(Player plyr : Bukkit.getOnlinePlayers())
                plyr.setScoreboard(board);
         
        }
    The code in between the objective is just my way of sorting the double from highest to lowest.
     
Thread Status:
Not open for further replies.