93
93
import java .util .UUID ;
94
94
import java .util .logging .Level ;
95
95
import java .util .logging .Logger ;
96
+ import java .util .regex .MatchResult ;
96
97
import java .util .regex .Matcher ;
97
98
import java .util .regex .Pattern ;
98
99
import org .yaml .snakeyaml .Yaml ;
@@ -1178,12 +1179,20 @@ public static String GetStringResource(Class path, String name) {
1178
1179
* @return
1179
1180
*/
1180
1181
public static String MCToANSIColors (String mes ) {
1181
- //Pull out the MC colors
1182
1182
if (mes == null ) {
1183
1183
return null ;
1184
1184
}
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.
1185
1195
return mes
1186
- .replaceAll ("(?i)§x(§[a-f0-9]){6}" , "" )
1187
1196
.replaceAll ("§0" , TermColors .BLACK )
1188
1197
.replaceAll ("§1" , TermColors .BLUE )
1189
1198
.replaceAll ("§2" , TermColors .GREEN )
@@ -1206,7 +1215,6 @@ public static String MCToANSIColors(String mes) {
1206
1215
.replaceAll ("§n" , TermColors .UNDERLINE )
1207
1216
.replaceAll ("§o" , TermColors .ITALIC )
1208
1217
.replaceAll ("§r" , TermColors .RESET );
1209
-
1210
1218
}
1211
1219
1212
1220
public static MCCommandSender GetInjectedPlayer (String name ) {
0 commit comments