From 47cadc768999de15f528b1d38e82362f4bf8d248 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Fri, 19 Jun 2020 19:29:01 +0100 Subject: [PATCH] Fix json data in chat --- .../translators/inventory/AnvilInventoryTranslator.java | 6 +++--- .../connector/ping/GeyserLegacyPingPassthrough.java | 3 ++- .../java/org/geysermc/connector/utils/MessageUtils.java | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java index d69f9f714..242d4ba4c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/AnvilInventoryTranslator.java @@ -26,8 +26,8 @@ package org.geysermc.connector.network.translators.inventory; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; -import com.github.steveice10.mc.protocol.data.message.Message; import com.github.steveice10.mc.protocol.data.message.MessageSerializer; +import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.nukkitx.protocol.bedrock.data.ContainerId; @@ -130,8 +130,8 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator { CompoundTag displayTag = tag.get("display"); if (displayTag != null) { String itemName = displayTag.get("Name").getValue().toString(); - Message message = MessageSerializer.fromString(itemName); - rename = message.toString(); + TextMessage message = (TextMessage) MessageSerializer.fromString(itemName); + rename = message.getText(); } else { rename = ""; } diff --git a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java index e770e91af..54978d5f4 100644 --- a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java +++ b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java @@ -29,6 +29,7 @@ package org.geysermc.connector.ping; import com.github.steveice10.mc.protocol.MinecraftConstants; import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.data.SubProtocol; +import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler; import com.github.steveice10.packetlib.Client; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; @@ -77,7 +78,7 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn try { this.client = new Client(connector.getConfig().getRemote().getAddress(), connector.getConfig().getRemote().getPort(), new MinecraftProtocol(SubProtocol.STATUS), new TcpSessionFactory()); this.client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> { - this.pingInfo = new GeyserPingInfo(info.getDescription().toString(), info.getPlayerInfo().getOnlinePlayers(), info.getPlayerInfo().getMaxPlayers()); + this.pingInfo = new GeyserPingInfo(((TextMessage) info.getDescription()).getText(), info.getPlayerInfo().getOnlinePlayers(), info.getPlayerInfo().getMaxPlayers()); this.client.getSession().disconnect(null); }); 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 9e32f0a9e..221a99176 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -28,6 +28,7 @@ package org.geysermc.connector.utils; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import com.github.steveice10.mc.protocol.data.message.Message; import com.github.steveice10.mc.protocol.data.message.MessageSerializer; +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.style.ChatColor; import com.github.steveice10.mc.protocol.data.message.style.ChatFormat; @@ -98,7 +99,7 @@ public class MessageUtils { message = MessageSerializer.fromJson(formatJson(object)); } - String messageText = message.toString(); + String messageText = (message instanceof TranslationMessage) ? ((TranslationMessage) message).getKey() : ((TextMessage) message).getText(); if (locale != null && shouldTranslate) { messageText = LocaleUtils.getLocaleString(messageText, locale); } @@ -135,8 +136,8 @@ public class MessageUtils { } public static String getBedrockMessage(Message message) { - if (isMessage(message.toString())) { - return getBedrockMessage(message.toString()); + if (isMessage(((TextMessage) message).getText())) { + return getBedrockMessage(((TextMessage) message).getText()); } else { return getBedrockMessage(MessageSerializer.toJsonString(message)); } @@ -276,7 +277,7 @@ public class MessageUtils { base += "f"; break; case RESET: - case NONE: + //case NONE: base += "r"; break; default: