Resource 1.16 Scoreboard objective score with RGB/Hex color

Discussion in 'Spigot Plugin Development' started by RedLime, Oct 18, 2020 at 11:39 AM.

  1. In 1.16 we can use the RGB and Hex colors to [ChatColor.of()] method.
    But it is not work on Scoreboard Objective table. it is work only objective's display.

    Code (Kotlin):
    val scoreboard = Bukkit.getScoreboardManager()!!.newScoreboard
    val objective = scoreboard.registerNewObjective("obj", "dummy", ChatColor.of(Color(255,0,0)).toString() + "" + ChatColor.BOLD + "Support RGB")
    //Objective Display Name with RGB or Hex Color is work!
    objective.displaySlot = DisplaySlot.SIDEBAR
    objective.getScore(ChatColor.of(Color(255,0,0)).toString() + "Not Support RGB :(").score = 1
    //But it didn't work with RGB or Hex Color :(
    player.setScoreboard(scoreboard)
    so how we got it do that?

    we can get it working with Team Suffix (or Prefix).

    Code (Kotlin):
    val scoreboard = Bukkit.getScoreboardManager()!!.newScoreboard
    val objective = scoreboard.registerNewObjective("obj", "dummy", ChatColor.of(Color(255,0,0)).toString() + "" + ChatColor.BOLD + "Support RGB")
    objective.displaySlot = DisplaySlot.SIDEBAR


    val team = scoreboard.getTeam("test") ?: scoreboard.registerNewTeam("test")
    team.suffix = ChatColor.of(Color(255,0,0)).toString() + "" + ChatColor.BOLD + "Support RGB"
    team.addEntry(ChatColor.translateAlternateColorCodes('&', "&a"))

    objective.getScore(ChatColor.translateAlternateColorCodes('&', "&a")).score = 1
    //It is work!

    player.setScoreboard(scoreboard)
    This is use the Minecraft color code to create a transparent name and add Team Suffix (or Prefix) to that player(name).

    [​IMG]
    It's Perfectly supprt RGB and Hex Color!
    Hope your good coding! :)
     
    #1 RedLime, Oct 18, 2020 at 11:39 AM
    Last edited: Oct 19, 2020 at 5:04 AM
    • Useful Useful x 2
    • Winner Winner x 1
    • Like Like x 1
  2. Can't wait to see a true rainbow updating scoreboard.
     
  3. oops, i mistakes on getScore() score name. i fixed it!
     
  4. awesome resource !