From fed3bf987eb031c33ce8d7cb9d639269be2c2397 Mon Sep 17 00:00:00 2001 From: R2VvcmdlUk5H <81434111+GeorgeRNG@users.noreply.github.com> Date: Fri, 26 Aug 2022 10:21:20 +0100 Subject: [PATCH] Patch #8 This works by only not adding message content if it has siblings --- .../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 9a9128c..19c0093 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();