File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
main/java/com/eternalcode/formatter/legacy
test/java/com/eternalcode/formatter/legacy Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ runPaper {
85
85
}
86
86
87
87
tasks.runServer {
88
- minecraftVersion(" 1.20 .4" )
88
+ minecraftVersion(" 1.21 .4" )
89
89
dependsOn(" shadowAll" )
90
90
pluginJars = files(" /build/libs/ChatFormatter v${project.version} .jar" )
91
91
}
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public final class Legacy {
19
19
public static final Pattern AMPERSAND_PATTERN = Pattern .compile ("(?i)" + AMPERSAND + "([0-9A-FK-ORX#])" );
20
20
public static final Pattern SHADOW_PATTERN = Pattern .compile ("(?i)" + SHADOW + "[0-9A-FK-ORX#]" );
21
21
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}" );
22
23
23
24
public static final Map <String , String > codeTranslations = new ImmutableMap .Builder <String , String >()
24
25
.put ("0" , "<black>" )
@@ -96,7 +97,12 @@ static String placeholderToAmpersand(String text) {
96
97
}
97
98
98
99
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 -> {
100
106
String hex = matchResult .group (1 );
101
107
return "<#" + hex + ">" ;
102
108
});
Original file line number Diff line number Diff line change @@ -50,4 +50,14 @@ void testLegacyToAdventure() {
50
50
assertEquals ("<red> SIEMA <#8376d3> <reset>test<green>!" , result );
51
51
}
52
52
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
+
53
63
}
You can’t perform that action at this time.
0 commit comments