Skip to content

Commit 0afd12d

Browse files
authored
GH-140 Bump run server version to 1.21.4 and add old legacy hex color transformers (#144)
* Bump run server version to 1.21.4 and add old legacy hex color transformers * Add test for legacy hex formatting
1 parent 2e26289 commit 0afd12d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ runPaper {
8585
}
8686

8787
tasks.runServer {
88-
minecraftVersion("1.20.4")
88+
minecraftVersion("1.21.4")
8989
dependsOn("shadowAll")
9090
pluginJars = files("/build/libs/ChatFormatter v${project.version}.jar")
9191
}

chatformatter-core/src/main/java/com/eternalcode/formatter/legacy/Legacy.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class Legacy {
1919
public static final Pattern AMPERSAND_PATTERN = Pattern.compile("(?i)" + AMPERSAND + "([0-9A-FK-ORX#])");
2020
public static final Pattern SHADOW_PATTERN = Pattern.compile("(?i)" + SHADOW + "[0-9A-FK-ORX#]");
2121
public static final Pattern HEX_PATTERN = Pattern.compile("(?i)" + AMPERSAND + "#([0-9A-F]{6})");
22+
public static final Pattern HEX_COLOR_PATTERN = Pattern.compile("(?i)&x(&[0-9A-F]){6}");
2223

2324
public static final Map<String, String> codeTranslations = new ImmutableMap.Builder<String, String>()
2425
.put("0", "<black>")
@@ -96,7 +97,12 @@ static String placeholderToAmpersand(String text) {
9697
}
9798

9899
public static String legacyToAdventure(String input) {
99-
String result = HEX_PATTERN.matcher(input).replaceAll(matchResult -> {
100+
String result = HEX_COLOR_PATTERN.matcher(input).replaceAll(matchResult -> {
101+
String hexColor = matchResult.group().replace("&x", "").replace("&", "");
102+
return "<#" + hexColor + ">";
103+
});
104+
105+
result = HEX_PATTERN.matcher(result).replaceAll(matchResult -> {
100106
String hex = matchResult.group(1);
101107
return "<#" + hex + ">";
102108
});

chatformatter-core/src/test/java/com/eternalcode/formatter/legacy/LegacyTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ void testLegacyToAdventure() {
5050
assertEquals("<red> SIEMA <#8376d3> <reset>test<green>!", result);
5151
}
5252

53+
@Test
54+
@DisplayName("Conversion of legacy hex formatting used in plugins like HexNicks default format")
55+
void testLegacyHexToAdventure() {
56+
String input = "&x&c&c&d&d&7&7&lSIEMA &x&7&7&5&5&4&4test&a!";
57+
58+
String result = Legacy.legacyToAdventure(input);
59+
60+
assertEquals("<#ccdd77><bold>SIEMA <#775544>test<green>!", result);
61+
}
62+
5363
}

0 commit comments

Comments
 (0)