Skip to content

Commit

Permalink
ElementTag.color: fallback to ColorTag attempt as last resort
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 17, 2022
1 parent 5cb6915 commit 7ea87e6
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -715,6 +715,14 @@ else if (colorName.startsWith("co@")) {
colorOut = ChatColor.COLOR_CHAR + "[color=" + colorStr + "]";
}
catch (IllegalArgumentException ex) {
ColorTag color = ColorTag.valueOf(colorName, attribute.context);
if (color != null) {
StringBuilder hex = new StringBuilder(Integer.toHexString(color.getColor().asRGB()));
while (hex.length() < 6) {
hex.insert(0, "0");
}
return new ElementTag(ChatColor.COLOR_CHAR + "[color=#" + hex + "]" + object.asString() + ChatColor.COLOR_CHAR + "[reset=color]");
}
attribute.echoError("Color '" + colorName + "' doesn't exist (for ElementTag.color[...]).");
return null;
}
Expand Down

0 comments on commit 7ea87e6

Please sign in to comment.