Use correct component serializer in ComponentHolder#getBinaryTag

This commit is contained in:
Gero
2025-02-28 15:01:20 +01:00
parent d4ea40a4a2
commit b8fe3577c9

View File

@@ -43,7 +43,6 @@ import net.kyori.adventure.nbt.LongBinaryTag;
import net.kyori.adventure.nbt.ShortBinaryTag; import net.kyori.adventure.nbt.ShortBinaryTag;
import net.kyori.adventure.nbt.StringBinaryTag; import net.kyori.adventure.nbt.StringBinaryTag;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -106,16 +105,14 @@ public class ComponentHolder {
public BinaryTag getBinaryTag() { public BinaryTag getBinaryTag() {
if (binaryTag == null) { if (binaryTag == null) {
// TODO: replace this with adventure-text-serializer-nbt // TODO: replace this with adventure-text-serializer-nbt
binaryTag = serialize(GsonComponentSerializer.gson().serializeToTree(getComponent())); binaryTag = serialize(ProtocolUtils.getJsonChatSerializer(version).serializeToTree(getComponent()));
} }
return binaryTag; return binaryTag;
} }
public static BinaryTag serialize(JsonElement json) { public static BinaryTag serialize(JsonElement json) {
if (json instanceof JsonPrimitive) { if (json instanceof JsonPrimitive jsonPrimitive) {
JsonPrimitive jsonPrimitive = (JsonPrimitive) json; if (jsonPrimitive.isNumber()) {
if (jsonPrimitive.isNumber()) {
Number number = json.getAsNumber(); Number number = json.getAsNumber();
if (number instanceof Byte) { if (number instanceof Byte) {