File tree Expand file tree Collapse file tree
main/java/com/eternalcode/formatter/legacy
test/java/com/eternalcode/formatter/legacy Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ runPaper {
8585}
8686
8787tasks.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}
Original file line number Diff line number Diff 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 });
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments