Fixed NONE colour formatting and cleaned up imports

This commit is contained in:
rtm516 2020-04-09 20:24:32 +01:00
parent 1e1d2f00ae
commit 9f1da99b71
3 changed files with 15 additions and 17 deletions

View file

@ -28,16 +28,12 @@ package org.geysermc.connector.utils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter; import lombok.Getter;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import java.io.*; import java.io.*;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.OffsetDateTime;
import java.util.*; import java.util.*;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;

View file

@ -26,16 +26,12 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; 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.*;
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.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import org.geysermc.connector.GeyserConnector;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -70,7 +66,7 @@ public class MessageUtils {
} }
} else { } else {
String builder = getFormat(message.getStyle().getFormats()) + String builder = getFormat(message.getStyle().getFormats()) +
getColor(message.getStyle().getColor()); getColorOrParent(message.getStyle());
builder += getTranslatedBedrockMessage(message, locale, false); builder += getTranslatedBedrockMessage(message, locale, false);
strings.add(builder); strings.add(builder);
} }
@ -84,7 +80,7 @@ public class MessageUtils {
} }
public static String getTranslationText(TranslationMessage message) { 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(); + "%" + message.getTranslationKey();
} }
@ -103,7 +99,7 @@ public class MessageUtils {
StringBuilder builder = new StringBuilder(messageText); StringBuilder builder = new StringBuilder(messageText);
for (Message msg : message.getExtra()) { for (Message msg : message.getExtra()) {
builder.append(getFormat(msg.getStyle().getFormats())); builder.append(getFormat(msg.getStyle().getFormats()));
builder.append(getColor(msg.getStyle().getColor())); builder.append(getColorOrParent(msg.getStyle()));
if (!(msg.getText() == null)) { if (!(msg.getText() == null)) {
boolean isTranslationMessage = (msg instanceof TranslationMessage); boolean isTranslationMessage = (msg instanceof TranslationMessage);
builder.append(getTranslatedBedrockMessage(msg, locale, isTranslationMessage)); builder.append(getTranslatedBedrockMessage(msg, locale, isTranslationMessage));
@ -136,6 +132,16 @@ public class MessageUtils {
return newMessage; 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) { private static String getColor(ChatColor color) {
String base = "\u00a7"; String base = "\u00a7";
switch (color) { switch (color) {
@ -188,6 +194,7 @@ public class MessageUtils {
base += "f"; base += "f";
break; break;
case RESET: case RESET:
case NONE:
base += "r"; base += "r";
break; break;
default: default:

View file

@ -25,16 +25,11 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import org.geysermc.connector.GeyserConnector;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;