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;
}
Aggregations