Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ runPaper {
}

tasks.runServer {
minecraftVersion("1.20.4")
minecraftVersion("1.21.4")
dependsOn("shadowAll")
pluginJars = files("/build/libs/ChatFormatter v${project.version}.jar")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class Legacy {
public static final Pattern AMPERSAND_PATTERN = Pattern.compile("(?i)" + AMPERSAND + "([0-9A-FK-ORX#])");
public static final Pattern SHADOW_PATTERN = Pattern.compile("(?i)" + SHADOW + "[0-9A-FK-ORX#]");
public static final Pattern HEX_PATTERN = Pattern.compile("(?i)" + AMPERSAND + "#([0-9A-F]{6})");
public static final Pattern HEX_COLOR_PATTERN = Pattern.compile("(?i)&x(&[0-9A-F]){6}");

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

public static String legacyToAdventure(String input) {
String result = HEX_PATTERN.matcher(input).replaceAll(matchResult -> {
String result = HEX_COLOR_PATTERN.matcher(input).replaceAll(matchResult -> {
String hexColor = matchResult.group().replace("&x", "").replace("&", "");
return "<#" + hexColor + ">";
});

result = HEX_PATTERN.matcher(result).replaceAll(matchResult -> {
String hex = matchResult.group(1);
return "<#" + hex + ">";
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ void testLegacyToAdventure() {
assertEquals("<red> SIEMA <#8376d3> <reset>test<green>!", result);
}

@Test
@DisplayName("Conversion of legacy hex formatting used in plugins like HexNicks default format")
void testLegacyHexToAdventure() {
String input = "&x&c&c&d&d&7&7&lSIEMA &x&7&7&5&5&4&4test&a!";

String result = Legacy.legacyToAdventure(input);

assertEquals("<#ccdd77><bold>SIEMA <#775544>test<green>!", result);
}

}
Loading