From f4cef48e4328df8b4e0a670da0d9ebb51b9ec1c9 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Sat, 20 Sep 2025 20:23:52 +0200 Subject: [PATCH] fix: use unrelocated gson for interacting with unrelocated APIs This fixes issues where plugins that relocate gson didn't work anymore because the previous changes in 7b025cdb were not taking into account that some plugins might relocate gson. --- .../platform/bukkit/MinecraftComponentSerializer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftComponentSerializer.java b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftComponentSerializer.java index 2809b1bd..acca8b85 100644 --- a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftComponentSerializer.java +++ b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/MinecraftComponentSerializer.java @@ -302,7 +302,7 @@ public static boolean isSupported() { final Object jsonElement = getOrThrow.invoke(result, (java.util.function.Function) RuntimeException::new); return gson().serializer().fromJson(jsonElement.toString(), Component.class); } else { - return gson().deserialize((String) TEXT_SERIALIZER_SERIALIZE.invoke(input)); + return gson().serializer().fromJson((String) TEXT_SERIALIZER_SERIALIZE.invoke(input), Component.class); } return gson().serializer().fromJson(element.toString(), Component.class); } catch (final Throwable error) { @@ -326,10 +326,12 @@ public static boolean isSupported() { throw new UnsupportedOperationException(error); } } else { + final JsonElement json = gson().serializer().toJsonTree(component); try { if (COMPONENTSERIALIZATION_CODEC_DECODE != null && CREATE_SERIALIZATION_CONTEXT != null) { final Object serializationContext = CREATE_SERIALIZATION_CONTEXT.bindTo(REGISTRY_ACCESS).invoke(JSON_OPS_INSTANCE); - final Object result = COMPONENTSERIALIZATION_CODEC_DECODE.invoke(serializationContext, gson().serializeToTree(component)); + final Object unRelocatedJsonElement = PARSE_JSON.invoke(JSON_PARSER_INSTANCE, json.toString()); + final Object result = COMPONENTSERIALIZATION_CODEC_DECODE.invoke(serializationContext, unRelocatedJsonElement); final Method getOrThrow = result.getClass().getMethod("getOrThrow", java.util.function.Function.class); final Object pair = getOrThrow.invoke(result, (java.util.function.Function) RuntimeException::new); final Method getFirst = pair.getClass().getMethod("getFirst");