mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Merge pull request #298 from rtm516/language-and-colour-fix
Fixed language processing and chat colours being reset for no reason
This commit is contained in:
commit
d8ff735626
4 changed files with 15 additions and 18 deletions
|
@ -69,7 +69,7 @@ public class JavaChatTranslator extends PacketTranslator<ServerChatPacket> {
|
||||||
List<String> paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale);
|
List<String> paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale);
|
||||||
textPacket.setParameters(paramsTranslated);
|
textPacket.setParameters(paramsTranslated);
|
||||||
|
|
||||||
textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, false), paramsTranslated));
|
textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, true), paramsTranslated));
|
||||||
} else {
|
} else {
|
||||||
textPacket.setNeedsTranslation(false);
|
textPacket.setNeedsTranslation(false);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue