From 84c064fc11be42e8c1afa3a0ae7325ae3514e2d9 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Fri, 14 May 2021 10:59:43 +0200 Subject: [PATCH] Fix legacy hover deserialization, add snapshot suffix to version --- build.gradle.kts | 2 +- .../protocol1_13to1_12_2/ChatRewriter.java | 6 ++++-- gradle/libs.versions.toml | 15 ++++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 39d8b9711..b7ddeb006 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.0.0-21w19a" + version = "4.0.0-21w19a-SNAPSHOT" description = "Allow newer clients to join older server versions." } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/ChatRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/ChatRewriter.java index 21ee211ab..e1ee475ce 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/ChatRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/ChatRewriter.java @@ -23,11 +23,13 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.libs.kyori.adventure.text.Component; import com.viaversion.viaversion.libs.kyori.adventure.text.format.TextDecoration; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.legacyimpl.NBTLegacyHoverEventSerializer; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.ComponentRewriter1_13; import com.viaversion.viaversion.rewriter.ComponentRewriter; -public class ChatRewriter { +public final class ChatRewriter { + public static final GsonComponentSerializer HOVER_GSON_SERIALIZER = GsonComponentSerializer.builder().emitLegacyHoverEvent().legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()).build(); private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13(); public static String legacyTextToJsonString(String message, boolean itemData) { @@ -52,7 +54,7 @@ public class ChatRewriter { public static String jsonToLegacyText(String value) { try { - Component component = GsonComponentSerializer.gson().deserialize(value); + Component component = HOVER_GSON_SERIALIZER.deserialize(value); return LegacyComponentSerializer.legacySection().serialize(component); } catch (Exception e) { Via.getPlatform().getLogger().warning("Error converting json text to legacy: " + value); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d47f401f9..9c2af2b48 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,9 +27,10 @@ velocity = "1.1.0-SNAPSHOT" [libraries] -adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" } -adventure-text-serializer-gson = { group = "net.kyori", name = "adventure-text-serializer-gson", version.ref = "adventure" } -adventure-text-serializer-legacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure" } +adventureApi = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" } +adventureTextSerializerGson = { group = "net.kyori", name = "adventure-text-serializer-gson", version.ref = "adventure" } +adventureTextSerializerGsonLegacy = { group = "net.kyori", name = "adventure-text-serializer-gson-legacy-impl", version.ref = "adventure" } +adventureTextSerializerLegacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure" } gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" } fastutil = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fastutil" } @@ -40,8 +41,8 @@ netty = { group = "io.netty", name = "netty-all", version.ref = "netty" } guava = { group = "com.google.guava", name = "guava", version.ref = "guava" } snakeYaml = { group = "org.yaml", name = "snakeyaml", version.ref = "snakeYaml" } -jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } -jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } +jupiterApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } +jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } checkerQual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerQual" } paper = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "paper" } @@ -54,5 +55,5 @@ velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = [bundles] -adventure = ["adventure-api", "adventure-text-serializer-gson", "adventure-text-serializer-legacy"] -junit = ["jupiter-api", "jupiter-engine"] +adventure = ["adventureApi", "adventureTextSerializerGson", "adventureTextSerializerGsonLegacy", "adventureTextSerializerLegacy"] +junit = ["jupiterApi", "jupiterEngine"]