From 969cc8c63bec4bd18985ab1ce1ee21dabd89267e Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 18 Aug 2025 12:12:46 +0300 Subject: [PATCH] Remove unnecessary gson component serializer wrapper --- .../text/GsonComponentSerializerWrapper.java | 83 ------------------- .../translator/text/MessageTranslator.java | 14 ++-- 2 files changed, 5 insertions(+), 92 deletions(-) delete mode 100644 core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java diff --git a/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java b/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java deleted file mode 100644 index aaf100009..000000000 --- a/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.text; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import org.checkerframework.checker.nullness.qual.NonNull; - -import java.util.function.UnaryOperator; - -/** - * A wrapper around a normal GsonComponentSerializer to accept null components. - */ -public record GsonComponentSerializerWrapper(GsonComponentSerializer source) implements GsonComponentSerializer { - - @Override - public @NonNull Gson serializer() { - return this.source.serializer(); - } - - @Override - public @NonNull UnaryOperator populator() { - return this.source.populator(); - } - - @Override - public @NonNull Component deserializeFromTree(@NonNull JsonElement input) { - // This has yet to be an issue, so it won't be overridden unless we have to - return this.source.deserializeFromTree(input); - } - - @Override - public @NonNull JsonElement serializeToTree(@NonNull Component component) { - return this.source.serializeToTree(component); - } - - @Override - public @NonNull Component deserialize(@NonNull String input) { - // See https://github.com/KyoriPowered/adventure/issues/447 - Component component = this.serializer().fromJson(input, Component.class); - if (component == null) { - return Component.empty(); - } - - return component; - } - - @Override - public @NonNull String serialize(@NonNull Component component) { - return this.source.serialize(component); - } - - @Override - public @NonNull Builder toBuilder() { - return this.source.toBuilder(); - } -} diff --git a/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java index 018d9a879..a58fb5e62 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java @@ -25,6 +25,10 @@ package org.geysermc.geyser.translator.text; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.regex.Pattern; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.TranslatableComponent; @@ -48,18 +52,12 @@ import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.ChatDecoration; import org.geysermc.geyser.text.DummyLegacyHoverEventSerializer; import org.geysermc.geyser.text.GeyserLocale; -import org.geysermc.geyser.text.GsonComponentSerializerWrapper; import org.geysermc.geyser.text.MinecraftTranslationRegistry; import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer; import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType; import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatTypeDecoration; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.regex.Pattern; - public class MessageTranslator { // These are used for handling the translations of the messages // Custom instead of TranslatableComponentRenderer#usingTranslationSource so we don't need to worry about finding a Locale class @@ -79,14 +77,12 @@ public class MessageTranslator { private static final Pattern RESET_PATTERN = Pattern.compile("(" + RESET + "){2,}"); static { - // Temporary fix for https://github.com/KyoriPowered/adventure/issues/447 - TODO resolve properly - GsonComponentSerializer source = DefaultComponentSerializer.get() + GSON_SERIALIZER = DefaultComponentSerializer.get() .toBuilder() // Use a custom legacy hover event deserializer since we don't use any of this data anyway, and // fixes issues where legacy hover events throw deserialization errors .legacyHoverEventSerializer(new DummyLegacyHoverEventSerializer()) .build(); - GSON_SERIALIZER = new GsonComponentSerializerWrapper(source); // Tell MCProtocolLib to use this serializer, too. DefaultComponentSerializer.set(GSON_SERIALIZER);