From b07433698a8e84bba4ef5d3d15917a8d6769ae93 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Sun, 16 Aug 2020 19:02:59 -0400 Subject: [PATCH] Translate specific messages (#1161) --- .../java/org/geysermc/connector/entity/Entity.java | 12 ++++-------- .../translators/java/JavaTitleTranslator.java | 7 ++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 1db5d2529f6..5e825e89260 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -32,8 +32,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; -import com.github.steveice10.mc.protocol.data.message.TextMessage; -import com.github.steveice10.mc.protocol.data.message.TranslationMessage; +import com.github.steveice10.mc.protocol.data.message.Message; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; import com.nukkitx.math.vector.Vector3f; @@ -318,13 +317,10 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s } break; case 2: // custom name - if (entityMetadata.getValue() instanceof TextMessage) { - TextMessage name = (TextMessage) entityMetadata.getValue(); - if (name != null) - metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name)); - } else if (entityMetadata.getValue() instanceof TranslationMessage) { - TranslationMessage message = (TranslationMessage) entityMetadata.getValue(); + if (entityMetadata.getValue() instanceof Message) { + Message message = (Message) entityMetadata.getValue(); if (message != null) + // Always translate even if it's a TextMessage since there could be translatable parameters metadata.put(EntityData.NAMETAG, MessageUtils.getTranslatedBedrockMessage(message, session.getClientData().getLanguageCode(), true)); } break; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java index 214413ab7a1..6a885e901b1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java @@ -39,15 +39,16 @@ public class JavaTitleTranslator extends PacketTranslator { @Override public void translate(ServerTitlePacket packet, GeyserSession session) { SetTitlePacket titlePacket = new SetTitlePacket(); + String locale = session.getClientData().getLanguageCode(); switch (packet.getAction()) { case TITLE: titlePacket.setType(SetTitlePacket.Type.TITLE); - titlePacket.setText(MessageUtils.getBedrockMessage(packet.getTitle())); + titlePacket.setText(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), locale)); break; case SUBTITLE: titlePacket.setType(SetTitlePacket.Type.SUBTITLE); - titlePacket.setText(MessageUtils.getBedrockMessage(packet.getTitle())); + titlePacket.setText(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), locale)); break; case CLEAR: case RESET: @@ -56,7 +57,7 @@ public void translate(ServerTitlePacket packet, GeyserSession session) { break; case ACTION_BAR: titlePacket.setType(SetTitlePacket.Type.ACTIONBAR); - titlePacket.setText(MessageUtils.getBedrockMessage(packet.getTitle())); + titlePacket.setText(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), locale)); break; case TIMES: titlePacket.setFadeInTime(packet.getFadeIn());