Search in sources :

Example 1 with LegacyFormat

use of net.kyori.adventure.text.serializer.legacy.LegacyFormat in project Prism-Bukkit by prism.

the class TypeUtils method from.

/**
 * Get Color.
 *
 * @param hex String.
 * @return ChatColor.
 */
public static TextColor from(String hex) {
    if (hex.length() == 2 && hex.startsWith("&")) {
        LegacyFormat format = LegacyComponentSerializer.parseChar(hex.charAt(1));
        if (format != null && format.color() != null) {
            return format.color();
        } else {
            return NamedTextColor.WHITE;
        }
    }
    if (hex.length() != 7 && !hex.startsWith("#")) {
        Prism.log("Could not decode as hex:" + hex);
        TextColor color = NamedTextColor.NAMES.value(hex);
        if (color != null) {
            return color;
        }
        return NamedTextColor.WHITE;
    }
    TextColor color = TextColor.fromHexString(hex);
    if (color == null) {
        return NamedTextColor.WHITE;
    }
    return color;
}
Also used : TextColor(net.kyori.adventure.text.format.TextColor) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) LegacyFormat(net.kyori.adventure.text.serializer.legacy.LegacyFormat)

Aggregations

NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)1 TextColor (net.kyori.adventure.text.format.TextColor)1 LegacyFormat (net.kyori.adventure.text.serializer.legacy.LegacyFormat)1