Skip to content

Commit

Permalink
also add element.color[...]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 1, 2019
1 parent 9abc90d commit a4d3626
Showing 1 changed file with 32 additions and 0 deletions.
Expand Up @@ -480,6 +480,38 @@ public static void registerTags() {
PropertyParser.<ElementTag>registerTag("obfuscate", (attribute, object) -> {
return new ElementTag(ChatColor.MAGIC + object.asString() + ChatColor.COLOR_CHAR + "[reset=k]");
});

// <--[tag]
// @attribute <ElementTag.color[<color>]>
// @returns ElementTag
// @group text manipulation
// @description
// Makes the input text colored by the input color. Equivalent to "<COLOR><ELEMENT_HERE><COLOR.end_format>"
// Color can be either a color name, or code.
// That is: ".color[gold]" and ".color[6]" are both valid.
// -->
PropertyParser.<ElementTag>registerTag("color", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
String colorName = attribute.getContext(1);
ChatColor color = null;
if (colorName.length() == 1) {
color = ChatColor.getByChar(colorName.charAt(0));
}
if (color == null) {
try {
color = ChatColor.valueOf(colorName);
}
catch (IllegalArgumentException ex) {
if (!attribute.hasAlternative()) {
Debug.echoError("Color '" + colorName + "' doesn't exist (for ElementTag.color[...]).");
}
return null;
}
}
return new ElementTag(color + object.asString() + ChatColor.COLOR_CHAR + "[reset=" + color.getChar() + "]");
});
}

@Override
Expand Down

0 comments on commit a4d3626

Please sign in to comment.