Saving ChatColor to config.

Discussion in 'Plugin Development' started by ChaddTheMan, Oct 29, 2014.

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

    ChaddTheMan

    Hi, any help with this question is appreciated, thanks in advance!
    I am trying to save a String with a ChatColor to the config with a '&' in front of a number.
    How can I replace this:
    Code:java
    1. ConfigString: '\xa7bThis is an aqua string'
    2. AnotherConfigString: '\xa7aThis is a lime string'
    3.  


    With this:
    Code:java
    1. ConfigString: '&bThis is an aqua string'
    2. AnotherConfigString: '&aThis is a lime string'


    I have tried doing this when saving it to the config:
    Code:java
    1. //A blue string
    2. String blueString = ChatColor.BLUE + "Blue!";
    3.  
    4. //Save it to config
    5. config.set("ConfigString", blueString.replace('\xa7', "&");
    6. And this is how I tried getting it from the config:
    7. String configString = ChatColor.stripColor( config.get("ConfigString") );
    8. String newConfigString = ChatColor.translateAlternateColorCodes('&', configString);


    Can someone please help me out with this?
     
  2. Offline

    Watto

    ChaddTheMan

    I don't see your problem? You should just be able to use the & is works for me :S
     
  3. repalce § with & (example: "§ahello" will be printed out like this: hello)

    you can use e.g. ChatColor.YELLOW or §e the result is the same

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  4. Offline

    es359

    ChaddTheMan Just use ChatColor.translateAlternateColorCodes('&', "");
     
  5. Offline

    fireblast709

    ChaddTheMan instead of stripColor, use replace(char, char). For the first char, you could use ChatColor.COLOR_CHAR.
     
  6. Offline

    Abs0rbed

    I'm pretty sure you can save chatcolors right into the config and then call ConfigurationSection.getColor(String path, ChatColor defaultVal)
     
  7. Offline

    fireblast709

    Abs0rbed thing is, he doesn't only want to save ChatColors, he wants to save a String with ChatColors in it :p.

    [EDIT] That aside, the config appears to support Color, not ChatColor.
     
    ChaddTheMan likes this.
  8. Offline

    ChaddTheMan


    Thanks, helped me fix my problem.
     
Thread Status:
Not open for further replies.

Share This Page