From c809ddb6183a31dc30953fa914283263c0718e53 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 10:13:47 +0100 Subject: [PATCH] Renamed translation method and cleaned up variable declaration --- .../platform/bukkit/GeyserBukkitConfiguration.java | 4 +++- .../bungeecord/GeyserBungeeConfiguration.java | 4 +++- .../platform/sponge/GeyserSpongeConfiguration.java | 4 +++- .../network/translators/java/JavaChatTranslator.java | 2 +- .../org/geysermc/connector/utils/MessageUtils.java | 12 +++++------- .../java/org/geysermc/connector/utils/Toolbox.java | 4 ++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index a99ac1e50..1ddda6528 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -102,7 +102,9 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { } @Override - public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } + public String getDefaultLocale() { + return config.getString("default-locale", "en_us"); + } @Override public Path getFloodgateKeyFile() { diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index 17a6ae0cf..420f8347e 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -103,7 +103,9 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { } @Override - public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } + public String getDefaultLocale() { + return config.getString("default-locale", "en_us"); + } @Override public Path getFloodgateKeyFile() { diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 18fb73081..7b6a89f15 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -106,7 +106,9 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { } @Override - public String getDefaultLocale() { return node.getNode("default-locale").getString("en_us"); } + public String getDefaultLocale() { + return node.getNode("default-locale").getString("en_us"); + } @Override public Path getFloodgateKeyFile() { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index 5db4a44ee..f58c61c9a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -62,7 +62,7 @@ public class JavaChatTranslator extends PacketTranslator { textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setNeedsTranslation(true); 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 { textPacket.setNeedsTranslation(false); textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); 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 854b3c1a2..8b32f0000 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -25,7 +25,6 @@ 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.message.ChatColor; import com.github.steveice10.mc.protocol.data.message.ChatFormat; @@ -38,7 +37,6 @@ import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import org.geysermc.connector.GeyserConnector; -import java.io.InputStream; import java.util.*; public class MessageUtils { @@ -77,7 +75,7 @@ public class MessageUtils { + "%" + message.getTranslationKey(); } - public static String getBedrockMessageWithTranslate(Message message, String locale) { + public static String getTranslatedBedrockMessage(Message message, String locale) { JsonParser parser = new JsonParser(); if (isMessage(message.getText())) { JsonObject object = parser.parse(message.getText()).getAsJsonObject(); @@ -100,12 +98,12 @@ public class MessageUtils { return builder.toString(); } - public static String getBedrockMessageWithTranslate(Message message) { - return getBedrockMessageWithTranslate(message, null); + public static String getTranslatedBedrockMessage(Message message) { + return getTranslatedBedrockMessage(message, null); } private static String getLocaleString(String messageText, String locale) { - HashMap localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); + Map localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); if (localeStrings == null) localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); @@ -116,7 +114,7 @@ public class MessageUtils { } public static String getBedrockMessage(Message message) { - return getBedrockMessageWithTranslate(message); + return getTranslatedBedrockMessage(message); } private static String getColor(ChatColor color) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 8ccd3aa3a..674a8bf7b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -52,7 +52,7 @@ public class Toolbox { public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); - public static final HashMap> LOCALE_MAPPINGS = new HashMap<>(); + public static final Map> LOCALE_MAPPINGS = new HashMap<>(); static { /* Load biomes */ @@ -127,7 +127,7 @@ public class Toolbox { } Iterator> localeIterator = locale.fields(); - HashMap langMap = new HashMap<>(); + Map langMap = new HashMap<>(); while (localeIterator.hasNext()) { Map.Entry entry = localeIterator.next(); langMap.put(entry.getKey(), entry.getValue().asText());