mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
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:
parent
a7f602e2ad
commit
9147d1036d
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user