Skip to content

Commit

Permalink
support essentials hex format in element.parse_color
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 24, 2020
1 parent 627cd04 commit 64b4ce7
Showing 1 changed file with 24 additions and 1 deletion.
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizen.utilities.TextWidthHelper;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.AsciiMatcher;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
Expand Down Expand Up @@ -46,6 +47,26 @@ private BukkitElementProperties(ElementTag element) {

ElementTag element;

public static AsciiMatcher HEX_MATCHER = new AsciiMatcher("abcdefABCDEF0123456789");

public static String replaceEssentialsHexColors(char prefix, String input) {
int hex = input.indexOf(prefix + "#");
while (hex != -1 && hex < input.length() + 8) {
StringBuilder converted = new StringBuilder(10);
converted.append(ChatColor.COLOR_CHAR).append("x");
for (int i = 0; i < 6; i++) {
char c = input.charAt(hex + 2 + i);
if (!HEX_MATCHER.isMatch(c)) {
return input;
}
converted.append(ChatColor.COLOR_CHAR).append(c);
}
input = input.substring(0, hex) + converted.toString() + input.substring(hex + 8);
hex = input.indexOf(prefix + "#", hex + 2);
}
return input;
}

public static void registerTags() {

// <--[tag]
Expand Down Expand Up @@ -299,7 +320,9 @@ public static void registerTags() {
if (attribute.hasContext(1)) {
prefix = attribute.getContext(1).charAt(0);
}
return new ElementTag(ChatColor.translateAlternateColorCodes(prefix, object.asString()));
String parsed = ChatColor.translateAlternateColorCodes(prefix, object.asString());
parsed = replaceEssentialsHexColors(prefix, parsed);
return new ElementTag(parsed);
});

// <--[tag]
Expand Down

0 comments on commit 64b4ce7

Please sign in to comment.