Skip to content

Commit e3e0d57

Browse files
committed
Added STRIP_COLOR
also reduced the amount of lines in REMOVE_TEXT because there was no optional value...
1 parent 497ab50 commit e3e0d57

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,23 +1675,35 @@ public enum ScriptActionType {
16751675
.arg("Text to remove", ScriptActionArgumentType.TEXT, b -> b.plural(true))
16761676
.category(ScriptActionCategory.TEXTS)
16771677
.action(ctx -> {
1678-
String result = null;
1679-
1680-
if(ctx.argMap().containsKey("Text to change"))
1681-
{
1682-
result = ctx.value("Text to change").asText();
1683-
}
1684-
else
1685-
{
1686-
result = ctx.value("Result").asText();
1687-
}
1678+
String result = ctx.value("Text to change").asText();
16881679

16891680
List<ScriptValue> textsToRemove = ctx.pluralValue("Text to remove");
16901681

16911682
for(int i = 0; i < textsToRemove.size(); i++) {
16921683
result = result.replace(textsToRemove.get(i).asText(), "");
16931684
}
16941685

1686+
ctx.context().setVariable(ctx.variable("Result").name(), new ScriptTextValue(result));
1687+
})),
1688+
1689+
STRIP_COLOR(builder -> builder.name("Strip Color from Text")
1690+
.description("Searches for color codes in a text and removes them.")
1691+
.icon(Items.WRITABLE_BOOK)
1692+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1693+
.arg("Text", ScriptActionArgumentType.TEXT, b -> b.optional(true))
1694+
.category(ScriptActionCategory.TEXTS)
1695+
.action(ctx -> {
1696+
String result = null;
1697+
1698+
if (ctx.argMap().containsKey("Text")) {
1699+
result = ctx.value("Text").asText();
1700+
} else {
1701+
result = ctx.value("Result").asText();
1702+
}
1703+
1704+
result = result.replaceAll("&x(&[0-9a-fA-F]){6}", "");
1705+
result = result.replaceAll("&[0-9a-fA-FlonmkrLONMKR]", "");
1706+
16951707
ctx.context().setVariable(ctx.variable("Result").name(), new ScriptTextValue(result));
16961708
}));
16971709

0 commit comments

Comments
 (0)