Solved Turning ChatColor into strings

Discussion in 'Plugin Development' started by Hex_27, Sep 26, 2015.

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

    Hex_27

    Is there a way to convert chatcolors to strings to be saved in a config?
    Example:
    ChatColor.DARK_RED + "hi"

    ||
    ||
    V

    &4hi
     
  2. Offline

    Googlelover1234

    @Hex_27
    You can use ChatColor#translateAlternateColorCodes(char c, String s)
    inside of your config. For example:

    Code:
    String message = ChatColor.translateAlternateColorCodes('&', getConfig().getString("test));
    
    player.sendMessage(message);
     
  3. Offline

    teej107

    @Hex_27 ChatColors can be saved in the config no problem.
     
  4. Offline

    Hex_27


    No. I don't want that. Read my post again. I want to do the literal opposite of what you're doing there.

    Can it be saved in the way I put in the Original Post? I need the users to understand the saved colorcodes
     
    Last edited: Sep 27, 2015
  5. Offline

    timtower Moderator Moderator

    Why not save them as readable and load them as translated strings in the onEnable?

    http://pastebin.com/a4B5Bw0x
    This is able to find the used ChatColors, you can modify it to return the strings as you need them.
     
  6. Offline

    FisheyLP

    If you print out ChatColor.DARK_RED it actually prints out "ยง4". I don't know what you want
     
  7. Offline

    Hex_27

    @FisheyLP I guess users can understand that, and there would be no need for me to write any code to change it. Thanks

    @FisheyLP okay, I just tried it, and no it didn't save it that way. It saved it like this
    \xa7[color]

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Sep 27, 2015
  8. Offline

    bwfcwalshy Retired Staff

  9. Offline

    Hex_27

  10. Offline

    teej107

    @Hex_27 This is the best option. It's simple and the users won't tell a difference.
     
    timtower likes this.
  11. Offline

    Hex_27

    Yep, this works :D. Just what I was looking for.

    I would. But, I need to save items with colored lores and display names in the game itself. It is much simpler with a colorize and decolorize method
     
Thread Status:
Not open for further replies.

Share This Page