From 9147d1036dfd4d7f7e5bf3f1db2e782eb088d71a Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Wed, 15 Jun 2022 11:31:42 -0400 Subject: [PATCH] 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. --- .../java/com/earth2me/essentials/utils/FormatUtil.java | 8 ++++++++ .../net/essentialsx/discord/util/ConsoleInjector.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/FormatUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/FormatUtil.java index 14eaef068..56ea126f1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/FormatUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/FormatUtil.java @@ -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) { diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java index e6ce349c8..24c301c91 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java @@ -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; }