Search in sources :

Example 1 with TextColor

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();
}
Also used : TextColor(net.kyori.text.format.TextColor) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)1 TextColor (net.kyori.text.format.TextColor)1