9393import java .util .UUID ;
9494import java .util .logging .Level ;
9595import java .util .logging .Logger ;
96+ import java .util .regex .MatchResult ;
9697import java .util .regex .Matcher ;
9798import java .util .regex .Pattern ;
9899import org .yaml .snakeyaml .Yaml ;
@@ -1178,12 +1179,20 @@ public static String GetStringResource(Class path, String name) {
11781179 * @return
11791180 */
11801181 public static String MCToANSIColors (String mes ) {
1181- //Pull out the MC colors
11821182 if (mes == null ) {
11831183 return null ;
11841184 }
1185+
1186+ // Convert RGB color codes to ANSI RGB color codes. Note that Windows command prompt ignores this.
1187+ mes = Pattern .compile ("(?i)§x(?:§([a-f0-9])){6}" ).matcher (mes ).replaceAll ((MatchResult res ) -> {
1188+ int red = Integer .parseInt (res .group (1 ) + res .group (2 ), 16 );
1189+ int green = Integer .parseInt (res .group (3 ) + res .group (4 ), 16 );
1190+ int blue = Integer .parseInt (res .group (5 ) + res .group (6 ), 16 );
1191+ return "\u001B [38;2;" + red + ";" + green + ";" + blue + "m" ;
1192+ });
1193+
1194+ // Convert preset MC color codes and markup codes to ANSI codes.
11851195 return mes
1186- .replaceAll ("(?i)§x(§[a-f0-9]){6}" , "" )
11871196 .replaceAll ("§0" , TermColors .BLACK )
11881197 .replaceAll ("§1" , TermColors .BLUE )
11891198 .replaceAll ("§2" , TermColors .GREEN )
@@ -1206,7 +1215,6 @@ public static String MCToANSIColors(String mes) {
12061215 .replaceAll ("§n" , TermColors .UNDERLINE )
12071216 .replaceAll ("§o" , TermColors .ITALIC )
12081217 .replaceAll ("§r" , TermColors .RESET );
1209-
12101218 }
12111219
12121220 public static MCCommandSender GetInjectedPlayer (String name ) {
0 commit comments