Renamed translation method and cleaned up variable declaration

This commit is contained in:
rtm516 2020-04-05 10:13:47 +01:00
parent 845c914492
commit c809ddb618
6 changed files with 17 additions and 13 deletions

View file

@ -102,7 +102,9 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration {
} }
@Override @Override
public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } public String getDefaultLocale() {
return config.getString("default-locale", "en_us");
}
@Override @Override
public Path getFloodgateKeyFile() { public Path getFloodgateKeyFile() {

View file

@ -103,7 +103,9 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration {
} }
@Override @Override
public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } public String getDefaultLocale() {
return config.getString("default-locale", "en_us");
}
@Override @Override
public Path getFloodgateKeyFile() { public Path getFloodgateKeyFile() {

View file

@ -106,7 +106,9 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration {
} }
@Override @Override
public String getDefaultLocale() { return node.getNode("default-locale").getString("en_us"); } public String getDefaultLocale() {
return node.getNode("default-locale").getString("en_us");
}
@Override @Override
public Path getFloodgateKeyFile() { public Path getFloodgateKeyFile() {

View file

@ -62,7 +62,7 @@ public class JavaChatTranslator extends PacketTranslator<ServerChatPacket> {
textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setType(TextPacket.Type.TRANSLATION);
textPacket.setNeedsTranslation(true); textPacket.setNeedsTranslation(true);
textPacket.setParameters(MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams())); textPacket.setParameters(MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams()));
textPacket.setMessage(MessageUtils.getBedrockMessageWithTranslate(packet.getMessage(), session.getClientData().getLanguageCode())); textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), session.getClientData().getLanguageCode()));
} else { } else {
textPacket.setNeedsTranslation(false); textPacket.setNeedsTranslation(false);
textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage()));

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import com.fasterxml.jackson.databind.JsonNode;
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.ChatColor;
import com.github.steveice10.mc.protocol.data.message.ChatFormat; import com.github.steveice10.mc.protocol.data.message.ChatFormat;
@ -38,7 +37,6 @@ import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import java.io.InputStream;
import java.util.*; import java.util.*;
public class MessageUtils { public class MessageUtils {
@ -77,7 +75,7 @@ public class MessageUtils {
+ "%" + message.getTranslationKey(); + "%" + message.getTranslationKey();
} }
public static String getBedrockMessageWithTranslate(Message message, String locale) { public static String getTranslatedBedrockMessage(Message message, String locale) {
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
if (isMessage(message.getText())) { if (isMessage(message.getText())) {
JsonObject object = parser.parse(message.getText()).getAsJsonObject(); JsonObject object = parser.parse(message.getText()).getAsJsonObject();
@ -100,12 +98,12 @@ public class MessageUtils {
return builder.toString(); return builder.toString();
} }
public static String getBedrockMessageWithTranslate(Message message) { public static String getTranslatedBedrockMessage(Message message) {
return getBedrockMessageWithTranslate(message, null); return getTranslatedBedrockMessage(message, null);
} }
private static String getLocaleString(String messageText, String locale) { private static String getLocaleString(String messageText, String locale) {
HashMap<String, String> localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); Map<String, String> localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase());
if (localeStrings == null) if (localeStrings == null)
localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale());
@ -116,7 +114,7 @@ public class MessageUtils {
} }
public static String getBedrockMessage(Message message) { public static String getBedrockMessage(Message message) {
return getBedrockMessageWithTranslate(message); return getTranslatedBedrockMessage(message);
} }
private static String getColor(ChatColor color) { private static String getColor(ChatColor color) {

View file

@ -52,7 +52,7 @@ public class Toolbox {
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
public static final HashMap<String, HashMap<String, String>> LOCALE_MAPPINGS = new HashMap<>(); public static final Map<String, Map<String, String>> LOCALE_MAPPINGS = new HashMap<>();
static { static {
/* Load biomes */ /* Load biomes */
@ -127,7 +127,7 @@ public class Toolbox {
} }
Iterator<Map.Entry<String, JsonNode>> localeIterator = locale.fields(); Iterator<Map.Entry<String, JsonNode>> localeIterator = locale.fields();
HashMap<String, String> langMap = new HashMap<>(); Map<String, String> langMap = new HashMap<>();
while (localeIterator.hasNext()) { while (localeIterator.hasNext()) {
Map.Entry<String, JsonNode> entry = localeIterator.next(); Map.Entry<String, JsonNode> entry = localeIterator.next();
langMap.put(entry.getKey(), entry.getValue().asText()); langMap.put(entry.getKey(), entry.getValue().asText());