Fix ANSI color codes not getting stripped on Paper (#4942)

Paper uses 0x7f as an intermediate character between adventure and its ANSI pattern converter, we need to strip this.
This commit is contained in:
Josh Roy 2022-06-15 11:31:42 -04:00 committed by GitHub
parent a7f602e2ad
commit 9147d1036d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -27,6 +27,7 @@ public final class FormatUtil {
private static final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-zA-Z]{2,3}(?:/\\S+)?)");
//Used to strip ANSI control codes from console
private static final Pattern ANSI_CONTROL_PATTERN = Pattern.compile("\u001B(?:\\[0?m|\\[38;2(?:;\\d{1,3}){3}m|\\[([0-9]{1,2}[;m]?){3})");
private static final Pattern PAPER_CONTROL_PATTERN = Pattern.compile("(?i)" + (char) 0x7f + "[0-9A-FK-ORX]");
private FormatUtil() {
}
@ -54,6 +55,13 @@ public final class FormatUtil {
return stripColor(input, ANSI_CONTROL_PATTERN);
}
public static String stripPaper(final String input) {
if (input == null) {
return null;
}
return stripColor(input, PAPER_CONTROL_PATTERN);
}
//This is the general permission sensitive message format function, checks for urls.
public static String formatMessage(final IUser user, final String permBase, final String input) {
if (input == null) {

View File

@ -62,8 +62,8 @@ public class ConsoleInjector extends AbstractAppender {
return;
}
// Ansi strip is for normal colors, normal strip is for 1.16 hex color codes as they are not formatted correctly
String entry = FormatUtil.stripFormat(FormatUtil.stripAnsi(event.getMessage().getFormattedMessage())).trim();
// Ansi strip is for normal colors, normal strip is for 1.16 hex color codes as they are not formatted correctly, adventure strip is for magic color char strip
String entry = FormatUtil.stripPaper(FormatUtil.stripFormat(FormatUtil.stripAnsi(event.getMessage().getFormattedMessage()))).trim();
if (entry.isEmpty()) {
return;
}