3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Added java -> bedrock lang conversions

Dieser Commit ist enthalten in:
rtm516 2020-04-04 17:25:38 +01:00
Ursprung ad3ca436b9
Commit 65277dc82a
2 geänderte Dateien mit 35 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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.getBedrockMessage(packet.getMessage())); textPacket.setMessage(MessageUtils.getBedrockMessageWithTranslate(packet.getMessage(), true));
} else { } else {
textPacket.setNeedsTranslation(false); textPacket.setNeedsTranslation(false);
textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage()));

Datei anzeigen

@ -76,14 +76,19 @@ public class MessageUtils {
+ "%" + message.getTranslationKey(); + "%" + message.getTranslationKey();
} }
public static String getBedrockMessage(Message message) { public static String getBedrockMessageWithTranslate(Message message, boolean convertLangStrings) {
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();
message = Message.fromJson(formatJson(object)); message = Message.fromJson(formatJson(object));
} }
StringBuilder builder = new StringBuilder(message.getText()); String messageText = message.getText();
if (convertLangStrings) {
messageText = getLangConversion(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(getColor(msg.getStyle().getColor()));
@ -94,6 +99,33 @@ public class MessageUtils {
return builder.toString(); return builder.toString();
} }
private static String getLangConversion(String messageText) {
switch (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":
return "chat.type.achievement";
default:
return messageText;
}
}
public static String getBedrockMessage(Message message) {
return getBedrockMessageWithTranslate(message, false);
}
private static String getColor(ChatColor color) { private static String getColor(ChatColor color) {
String base = "\u00a7"; String base = "\u00a7";
switch (color) { switch (color) {