From aed1eef6e183e4b42beb42181f15343999f8f3e0 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 15 Dec 2020 11:24:02 -0500 Subject: [PATCH] Update Adventure and fix some legacy hover events (#1681) --- connector/pom.xml | 12 +++++++++--- .../network/translators/chat/MessageTranslator.java | 13 +++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index b1f088101..b71fdcb6a 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -153,19 +153,25 @@ net.kyori adventure-api - 4.2.0 + 4.3.0 compile net.kyori adventure-text-serializer-gson - 4.2.0 + 4.3.0 compile net.kyori adventure-text-serializer-legacy - 4.2.0 + 4.3.0 + compile + + + net.kyori + adventure-text-serializer-gson-legacy-impl + 4.3.0 compile diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/chat/MessageTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/chat/MessageTranslator.java index 79ce856ad..32a9d6e0b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/chat/MessageTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/chat/MessageTranslator.java @@ -25,26 +25,32 @@ package org.geysermc.connector.network.translators.chat; +import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.renderer.TranslatableComponentRenderer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.gson.legacyimpl.NBTLegacyHoverEventSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.LanguageUtils; -import java.util.*; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; public class MessageTranslator { // These are used for handling the translations of the messages private static final TranslatableComponentRenderer RENDERER = TranslatableComponentRenderer.usingTranslationSource(new MinecraftTranslationRegistry()); - // Construct our own {@link GsonComponentSerializer} encase we need to change anything + // Construct our own {@link GsonComponentSerializer} since we need to change a setting private static final GsonComponentSerializer GSON_SERIALIZER = GsonComponentSerializer.builder() + // Specify that we may be expecting legacy hover events + .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()) .build(); // Store team colors for player names @@ -61,6 +67,9 @@ public class MessageTranslator { TEAM_FORMATS.put(TeamColor.BOLD, TextDecoration.BOLD); TEAM_FORMATS.put(TeamColor.STRIKETHROUGH, TextDecoration.STRIKETHROUGH); TEAM_FORMATS.put(TeamColor.ITALIC, TextDecoration.ITALIC); + + // Tell MCProtocolLib to use our serializer + DefaultComponentSerializer.set(GSON_SERIALIZER); } /**