From 9f1da99b71b23f7d862d0ba5023bb6a989e654a4 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 20:24:32 +0100 Subject: [PATCH] Fixed NONE colour formatting and cleaned up imports --- .../geysermc/connector/utils/LocaleUtils.java | 4 ---- .../connector/utils/MessageUtils.java | 23 ++++++++++++------- .../geysermc/connector/utils/WebUtils.java | 5 ---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index b5329dff9..e8555eb02 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -28,16 +28,12 @@ package org.geysermc.connector.utils; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; import org.geysermc.connector.GeyserConnector; import java.io.*; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.time.OffsetDateTime; import java.util.*; import java.util.zip.ZipFile; diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 85fb6eb93..e58c5d74d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -26,16 +26,12 @@ package org.geysermc.connector.utils; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; -import com.github.steveice10.mc.protocol.data.message.ChatColor; -import com.github.steveice10.mc.protocol.data.message.ChatFormat; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.TranslationMessage; +import com.github.steveice10.mc.protocol.data.message.*; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import org.geysermc.connector.GeyserConnector; import java.util.*; import java.util.regex.Matcher; @@ -70,7 +66,7 @@ public class MessageUtils { } } else { String builder = getFormat(message.getStyle().getFormats()) + - getColor(message.getStyle().getColor()); + getColorOrParent(message.getStyle()); builder += getTranslatedBedrockMessage(message, locale, false); strings.add(builder); } @@ -84,7 +80,7 @@ public class MessageUtils { } public static String getTranslationText(TranslationMessage message) { - return getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor()) + return getFormat(message.getStyle().getFormats()) + getColorOrParent(message.getStyle()) + "%" + message.getTranslationKey(); } @@ -103,7 +99,7 @@ public class MessageUtils { StringBuilder builder = new StringBuilder(messageText); for (Message msg : message.getExtra()) { builder.append(getFormat(msg.getStyle().getFormats())); - builder.append(getColor(msg.getStyle().getColor())); + builder.append(getColorOrParent(msg.getStyle())); if (!(msg.getText() == null)) { boolean isTranslationMessage = (msg instanceof TranslationMessage); builder.append(getTranslatedBedrockMessage(msg, locale, isTranslationMessage)); @@ -136,6 +132,16 @@ public class MessageUtils { return newMessage; } + private static String getColorOrParent(MessageStyle style) { + ChatColor chatColor = style.getColor(); + + if (chatColor == ChatColor.NONE) { + return getColor(style.getParent().getColor()); + } + + return getColor(chatColor); + } + private static String getColor(ChatColor color) { String base = "\u00a7"; switch (color) { @@ -188,6 +194,7 @@ public class MessageUtils { base += "f"; break; case RESET: + case NONE: base += "r"; break; default: diff --git a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java index a155f0b95..065d683a0 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java @@ -25,16 +25,11 @@ package org.geysermc.connector.utils; -import org.geysermc.connector.GeyserConnector; - import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption;