Solved Scoreboard Error

Discussion in 'Spigot Plugin Development' started by LazyDev, May 11, 2016.

  1. This is My Scoreboard
    img.png
    look at score number 4 and 7 not working
    Code (Text):
          public void setScoreboard(Player p)
          {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective o = board.registerNewObjective("dummy", "scoreboard");
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
              o.setDisplayName("§8»§6 Gamers Revolution §8«");
             
                o.getScore("§eName:").setScore(9);
                if (p.hasPermission("Owner")) {
                  o.getScore("§4" + p.getDisplayName()).setScore(8);
                } else if (p.hasPermission("Dev")) {
                  o.getScore("§b" + p.getDisplayName()).setScore(8);
                }else if (p.hasPermission("Admin")) {
                  o.getScore("§4" + p.getDisplayName()).setScore(8);
                } else if (p.hasPermission("Moderator")) {
                  o.getScore("§c" + p.getDisplayName()).setScore(8);
                } else if (p.hasPermission("Builder")) {
                  o.getScore("§3" + p.getDisplayName()).setScore(8);
                } else if (p.hasPermission("Premium")) {
                  o.getScore("§6" + p.getDisplayName()).setScore(8);
                } else if (p.hasPermission("Youtuber")) {
                  o.getScore("§5" + p.getDisplayName()).setScore(8);
                } else {
                  o.getScore("§7" + p.getDisplayName()).setScore(8);
                }
               
                o.getScore("").setScore(7);
               
            o.getScore("§eRank:").setScore(6);
            if (p.hasPermission("Owner")) {
              o.getScore("§4Owner").setScore(5);
            }else if (p.hasPermission("Dev")) {
              o.getScore("§bDeveloper").setScore(5);
            } else if (p.hasPermission("Admin")) {
              o.getScore("§4Admin").setScore(5);
            } else if (p.hasPermission("Moderator")) {
              o.getScore("§cModerator").setScore(5);
            } else if (p.hasPermission("Builder")) {
              o.getScore("§3Builder").setScore(5);
            } else if (p.hasPermission("Premium")) {
              o.getScore("§6Premium").setScore(5);
            } else if (p.hasPermission("Youtuber")) {
              o.getScore("§5Youtuber").setScore(5);
            } else {
              o.getScore("§7Player").setScore(5);
            }
           
            o.getScore("").setScore(4);
            o.getScore("§eCoins:").setScore(3);
            o.getScore("§6" + Main.getCoins(p)).setScore(2);
            o.getScore("").setScore(1);
            p.setScoreboard(board);
          }
     
  2. Your code is doing:

    o.getScore("").setScore(7);
    o.getScore("").setScore(4);
    o.getScore("").setScore(1);

    which is setting an empty string's value 3 times, so only the last one counts.

    The way to get around this might be to do something like:

    o.getScore(ChatColor.BLACK.toString()).setScore(7);
    o.getScore(ChatColor.GRAY.toString()).setScore(4);
    ... etc

    However I'm sure there is a better way - I'm not familiar enough with the scoreboard API to know. This should work for now though.