use of net.kyori.text.format.TextColor in project VoxelGamesLibv2 by VoxelGamesLib.
the class Lang method parseLegacyFormat.
/**
* Parses a string into the legacy chat format that is still used for some sutff in minecraft...<br> Mostly handles
* color variables
*
* @param string the input string
* @return the properly formatted legacy string
*/
@Nonnull
public static String parseLegacyFormat(@Nonnull String string) {
StringBuilder stringBuilder = new StringBuilder();
String[] tokens = string.split("\\{|}");
TextColor savedColor = TextColor.WHITE;
outer: for (String token : tokens) {
for (TextColor color : TextColor.values()) {
if (color.name().equalsIgnoreCase(token)) {
savedColor = color;
continue outer;
}
}
// why don't you just expose getCode?....
stringBuilder.append(ChatColor.COLOR_CHAR).append(// no COLOR_CHAR in text
savedColor.toString().substring(1, 1)).append(token);
}
return stringBuilder.toString();
}