Some people have a hard time figuring out the &<colorcode> stuff in configs, so if you want your configs to be a bit simpler and easier to understand then you can use this code. With this you can put something like <red> in your text and it will be replaced with red. It's not case sensitive so it will work for <red>, <RED> and even <rEd> Heres a list of the Strings it will replace (not case sensitive ofcouse): Code: <black> <dark_blue> <dark_green> <dark_aqua> <dark_red> <dark_purple> <gold> <gray> <dark_gray> <blue> <green> <aqua> <red> <light_purple> <yellow> <white> Now for the code! Code:java public static String format(String string) { String s = string; for (ChatColor color : ChatColor.values()) { s = s.replaceAll("(?i)<" + color.name() + ">", "" + color); } return s;} How to use it: Code:java String myString = "This <red>message <yellow>is <light_purple>AWESOME!";player.sendMessage(format(myString)); Here is how it works: It loops through every ChatColor and checks your String if it has the color with < and > surrounding it, if it has, then it replaces it with the ChatColor it matches. The (?i) part just makes sure it's not case sensitive. You can use this as you wish and you dont have to credit me or anything(I dont mind if you do though)
Code: /** * Takes a string and replaces &# color codes with ChatColors * * @param message * @return */ private String replaceColors (String message) { return message.replaceAll("(?i)&([a-f0-9])", "\u00A7$1"); } http://www.minecraftwiki.net/wiki/Classic_server_protocol#Color_Codes I used to use a method similar to the OP - but it's not very optimal as it requires looping/regexing 16 times. the above works for all color codes (case insensetive) using the &# format as seen on the wiki. I'd suggest using something similar to this as it's about 16x faster. t3hk0d3 mentioned using this on irc after I looked into just doing standard character checking, and after doing some time tests (and fixing the original method) this one has the best time results. I realize your code post was more going for legibility, and it will work in the end, just wanted to show a way to do it that is very quick.
how do i use that with this string builder Code:java public static String format(String string) { String s = string; for (ChatColor color : ChatColor.values()) { s = s.replaceAll("(?i)<" + color.name() + ">", "" + color); } return s;}
But this has a neat way of doing it... Instead of doing &e you'd do <yellow> or something. More user friendly, IMO