From 13932a6ca3267eab284d6b991eeafd72103839f5 Mon Sep 17 00:00:00 2001 From: themode Date: Fri, 13 Nov 2020 00:28:22 +0100 Subject: [PATCH] Removed RichMessage format retention, should be done manually. + cleanup --- .../net/minestom/server/chat/RichMessage.java | 72 ++++++------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/src/main/java/net/minestom/server/chat/RichMessage.java b/src/main/java/net/minestom/server/chat/RichMessage.java index 4b855b3de..0818e7909 100644 --- a/src/main/java/net/minestom/server/chat/RichMessage.java +++ b/src/main/java/net/minestom/server/chat/RichMessage.java @@ -42,18 +42,30 @@ public class RichMessage extends JsonMessage { Check.notNull(coloredText, "ColoredText cannot be null"); RichMessage richMessage = new RichMessage(); - appendText(richMessage, coloredText, FormatRetention.ALL); + appendText(richMessage, coloredText); return richMessage; } - private static void appendText(@NotNull RichMessage richMessage, @NotNull ColoredText coloredText, - @NotNull FormatRetention formatRetention) { - RichComponent component = new RichComponent(coloredText, formatRetention); + private static void appendText(@NotNull RichMessage richMessage, @NotNull ColoredText coloredText) { + RichComponent component = new RichComponent(coloredText); richMessage.components.add(component); richMessage.currentComponent = component; } + /** + * Adds a new rich component to the message. + * + * @param coloredText the text composing the rich component + * @return the rich message + */ + public RichMessage append(@NotNull ColoredText coloredText) { + Check.notNull(coloredText, "ColoredText cannot be null"); + + appendText(this, coloredText); + return this; + } + /** * Sets the click event of the current rich component. * @@ -87,31 +99,6 @@ public class RichMessage extends JsonMessage { return this; } - /** - * Adds a new rich component to the message. - * - * @param coloredText the text composing the rich component - * @param formatRetention the format retention of the added component - * @return the rich message - */ - public RichMessage append(@NotNull ColoredText coloredText, @NotNull FormatRetention formatRetention) { - Check.notNull(coloredText, "ColoredText cannot be null"); - - appendText(this, coloredText, formatRetention); - return this; - } - - /** - * Adds a new rich component to the message, - * the format retention is set to {@link FormatRetention#ALL}. - * - * @param coloredText the text composing the rich component - * @return the rich message - */ - public RichMessage append(@NotNull ColoredText coloredText) { - return append(coloredText, FormatRetention.ALL); - } - @NotNull @Override public JsonObject getJsonObject() { @@ -121,18 +108,14 @@ public class RichMessage extends JsonMessage { if (cacheComponents.isEmpty()) return new JsonObject(); - RichComponent firstComponent = cacheComponents.remove(0); - List firstComponentObjects = getComponentObject(firstComponent); - JsonObject mainObject = firstComponentObjects.remove(0); - - if (cacheComponents.isEmpty() && firstComponentObjects.isEmpty()) - return mainObject; + // The main object contains the extra array, with an empty text to do not share its state with the others + JsonObject mainObject = new JsonObject(); + mainObject.addProperty("text", ""); + // The extra array contains all the components JsonArray extraArray = new JsonArray(); - for (JsonObject firstComponentObject : firstComponentObjects) { - extraArray.add(firstComponentObject); - } + // Add all the components for (RichComponent component : cacheComponents) { List componentObjects = getComponentObject(component); for (JsonObject componentObject : componentObjects) { @@ -205,24 +188,18 @@ public class RichMessage extends JsonMessage { return eventObject; } - public enum FormatRetention { - ALL, CLICK_EVENT, HOVER_EVENT, NONE - } - /** * Represents a {@link ColoredText} with a click and hover event (can be null). */ private static class RichComponent { private final ColoredText text; - private final FormatRetention formatRetention; private ChatClickEvent clickEvent; private ChatHoverEvent hoverEvent; private String insertion; - private RichComponent(@NotNull ColoredText text, @NotNull FormatRetention formatRetention) { + private RichComponent(@NotNull ColoredText text) { this.text = text; - this.formatRetention = formatRetention; } @NotNull @@ -230,11 +207,6 @@ public class RichMessage extends JsonMessage { return text; } - @NotNull - public FormatRetention getFormatRetention() { - return formatRetention; - } - @Nullable public ChatClickEvent getClickEvent() { return clickEvent;