From 135e1ecc775b16b310f8417ad79fda256a8955f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AE=28gorg=29?= <81434111+GeorgeRNG@users.noreply.github.com> Date: Fri, 26 Aug 2022 11:22:34 +0100 Subject: [PATCH] Reapply chat fixes for 1.18 Fixes #8 in the same way patch #9 works. Untested --- .../dfscript/util/ComponentUtil.java | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java b/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java index f350535..c464aae 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java @@ -55,35 +55,39 @@ public static MutableText fromString(String message) { public static String toFormattedString(Text message) { StringBuilder result = new StringBuilder(); - Style style = message.getStyle(); + if(message.getSiblings().isEmpty()){ + Style style = message.getStyle(); - String format = ""; + String format = ""; - if (style.getColor() != null) { - format += "§x§" + String.join("§", String.format("%06X", style.getColor().getRgb()).split("")); - } - - if (style.isBold()) { - format += "§l"; - } - if (style.isItalic()) { - format += "§o"; - } - if (style.isUnderlined()) { - format += "§n"; - } - if (style.isStrikethrough()) { - format += "§m"; - } - if (style.isObfuscated()) { - format += "§k"; - } + if (style.getColor() != null) { + format += "§x§" + String.join("§", String.format("%06X", style.getColor().getRgb()).split("")); + } - result.append(format); - result.append(message.getString()); + if (style.isBold()) { + format += "§l"; + } + if (style.isItalic()) { + format += "§o"; + } + if (style.isUnderlined()) { + format += "§n"; + } + if (style.isStrikethrough()) { + format += "§m"; + } + if (style.isObfuscated()) { + format += "§k"; + } - for (Text sibling : message.getSiblings()) { - result.append(toFormattedString(sibling)); + result.append(format); + result.append(message.getString()); + } + else { + for (Text sibling : message.getSiblings()) { + result.append("§r"); + result.append(toFormattedString(sibling)); + } } return result.toString();