forked from GeyserMC/Geyser
Moved to json file lang mapping
This commit is contained in:
parent
7298e2ff3f
commit
c1e00e3614
1 changed files with 22 additions and 30 deletions
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
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;
|
||||||
|
@ -36,11 +37,28 @@ 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 java.util.ArrayList;
|
import java.io.InputStream;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
private static final HashMap<String, String> LANG_MAPPINGS = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
/* Load the language mappings */
|
||||||
|
InputStream stream = Toolbox.getResource("mappings/lang.json");
|
||||||
|
JsonNode lang;
|
||||||
|
try {
|
||||||
|
lang = Toolbox.JSON_MAPPER.readTree(stream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError("Unable to load Java lang mappings", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Map.Entry<String, JsonNode>> langIterator = lang.fields();
|
||||||
|
while (langIterator.hasNext()) {
|
||||||
|
Map.Entry<String, JsonNode> entry = langIterator.next();
|
||||||
|
LANG_MAPPINGS.put(entry.getKey(), entry.getValue().asText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> getTranslationParams(Message[] messages) {
|
public static List<String> getTranslationParams(Message[] messages) {
|
||||||
List<String> strings = new ArrayList<>();
|
List<String> strings = new ArrayList<>();
|
||||||
|
@ -100,33 +118,7 @@ public class MessageUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getLangConversion(String messageText) {
|
private static String getLangConversion(String messageText) {
|
||||||
switch (messageText) {
|
return LANG_MAPPINGS.getOrDefault(messageText, messageText);
|
||||||
case "block.minecraft.bed.occupied":
|
|
||||||
return "tile.bed.occupied";
|
|
||||||
case "block.minecraft.bed.too_far_away":
|
|
||||||
return "tile.bed.tooFar";
|
|
||||||
case "block.minecraft.bed.not_safe":
|
|
||||||
return "tile.bed.notSafe";
|
|
||||||
case "block.minecraft.bed.no_sleep":
|
|
||||||
return "tile.bed.noSleep";
|
|
||||||
case "block.minecraft.bed.not_valid":
|
|
||||||
return "tile.bed.notValid";
|
|
||||||
case "block.minecraft.bed.set_spawn":
|
|
||||||
return "tile.bed.respawnSet";
|
|
||||||
|
|
||||||
case "chat.type.advancement.task":
|
|
||||||
case "chat.type.advancement.challenge":
|
|
||||||
case "chat.type.advancement.goal":
|
|
||||||
return "chat.type.achievement";
|
|
||||||
|
|
||||||
case "commands.teleport.success.entity.single":
|
|
||||||
return "commands.tp.success";
|
|
||||||
case "commands.teleport.success.location.single":
|
|
||||||
return "commands.tp.success.coordinates";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return messageText;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBedrockMessage(Message message) {
|
public static String getBedrockMessage(Message message) {
|
||||||
|
|
Loading…
Reference in a new issue