1.15.2 Color translating returns as null in player name

Discussion in 'Spigot Plugin Development' started by Wrathguy78, Mar 23, 2020.

  1. In my setRank function, I have it so it pulls the color codes out of my config and translates them inside a variable with the ChatColor.translateAlernateColorCodes method. the string. I then put that code inside the setDisplayName method. The translating of the color codes does not work. It gets returned as null.

    Code (Text):
    public void setRank(Player player) {
            String getRank = plugin.getConfig().getString("players." + player.getUniqueId().toString() + ".ranks");
            String pc =  plugin.getConfig().getString("players." + player.getUniqueId().toString() + ".playercolor");
            String rc = plugin.getConfig().getString("players." + player.getUniqueId().toString() + ".rankcolor");
            String name = ChatColor.translateAlternateColorCodes('&', ChatColor.DARK_AQUA + "-" + rc + getRank + ChatColor.DARK_AQUA + "- " + pc + player.getName() + ChatColor.WHITE);
            player.setDisplayName(name);
            player.setPlayerListName(name);
        }
    upload_2020-3-23_15-49-2.png
     
  2. Can you give us an example of your config.yml?
     
  3. Code (Text):
    players:
      503536ed-9ad4-4277-88f1-5b15ec49d050:
        ranks: Owner
        playercolor: &7
        rankcolor: &8
     
  4. I'm not a very good programmer but have you try to display on console the string result of
    Code (Text):
    ChatColor.DARK_AQUA + "-" + rc + getRank + ChatColor.DARK_AQUA + "- " + pc + player.getName() + ChatColor.WHITE
    ?

    To learn programming I do a lot of "try and fail". I make a lot of test by displaying data on console.
     
  5. When I do that I get
    Code (Text):
     º3-nullOwnerº3- nullUranium_Apeºf
    Which is basically the same result
     
  6. Print rc and pc individually without translating, are they what the config says?
     
  7. might need to wrap the keys playercolor and rankcolor with '' in your yaml file
     
    • Like Like x 1
  8. that worked thanks
     
  9. Try putting a default value in the .getString() methods, when the plugin can't find the string it will return the default value. Also try to wrap those color codes with '' as Warren1001 said.
    Example with default value:
    Code (Java):
    String pc =  plugin.getConfig().getString("players." + player.getUniqueId().toString() + ".playercolor", "");
     
    • Like Like x 1