From cd60d3a8f9a764a41b3d7f238ccb9a8d65a8eb7a Mon Sep 17 00:00:00 2001
From: Josh Roy <10731363+JRoy@users.noreply.github.com>
Date: Mon, 22 Feb 2021 21:43:05 -0500
Subject: [PATCH] Fix Log4J converter not parsing hex without named colors
 (#5228)

---
 ...upport-for-hex-color-codes-in-console.patch | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/Spigot-Server-Patches/Add-support-for-hex-color-codes-in-console.patch b/Spigot-Server-Patches/Add-support-for-hex-color-codes-in-console.patch
index 92ccfa5898..c4d63fcbef 100644
--- a/Spigot-Server-Patches/Add-support-for-hex-color-codes-in-console.patch
+++ b/Spigot-Server-Patches/Add-support-for-hex-color-codes-in-console.patch
@@ -13,6 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@
 +package io.papermc.paper.console;
 +
++import net.kyori.adventure.text.format.TextColor;
 +import net.minecrell.terminalconsole.TerminalConsoleAppender;
 +import org.apache.logging.log4j.core.LogEvent;
 +import org.apache.logging.log4j.core.config.Configuration;
@@ -22,7 +23,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +import org.apache.logging.log4j.util.PerformanceSensitive;
 +import org.apache.logging.log4j.util.PropertiesUtil;
 +
-+import java.awt.*;
 +import java.util.List;
 +import java.util.regex.Matcher;
 +import java.util.regex.Pattern;
@@ -102,7 +102,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        }
 +
 +        boolean useAnsi = ansi && TerminalConsoleAppender.isAnsiSupported();
-+        String content = useAnsi ? convertRGBColors(toAppendTo.substring(start)) : stripRGBColors(toAppendTo.substring(start));
++        String content = toAppendTo.substring(start);
++        content = useAnsi ? convertRGBColors(content) : stripRGBColors(content);
 +        format(content, toAppendTo, start, useAnsi);
 +    }
 +
@@ -111,10 +112,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        StringBuffer buffer = new StringBuffer();
 +        while (matcher.find()) {
 +            String s = matcher.group().replace(String.valueOf(COLOR_CHAR), "").replace('x', '#');
-+            Color color = Color.decode(s);
-+            int red = color.getRed();
-+            int blue = color.getBlue();
-+            int green = color.getGreen();
++            TextColor color = TextColor.fromHexString(s);
++            int red = color.red();
++            int blue = color.blue();
++            int green = color.green();
 +            String replacement = String.format(RGB_ANSI, red, green, blue);
 +            matcher.appendReplacement(buffer, replacement);
 +        }
@@ -136,6 +137,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        int next = s.indexOf(COLOR_CHAR);
 +        int last = s.length() - 1;
 +        if (next == -1 || next == last) {
++            result.setLength(start);
++            result.append(s);
++            if (ansi) {
++                result.append(ANSI_RESET);
++            }
 +            return;
 +        }
 +