Use JsonSerializationContext#serialize instead of recursion for AdventureComponents - fixes #5580 and #5371

This commit is contained in:
jmp 2021-05-06 03:32:52 -07:00 committed by Jason
parent 8fcef3c1f6
commit 0aea6c2ff3
2 changed files with 13 additions and 5 deletions

View File

@ -1020,7 +1020,7 @@ index dc8cc8d6c00176c8562086282f726dc1b24b2c65..2f6da89d6b25ba5144ec15b1bf0e8ed1
packetdataserializer.d(integer); packetdataserializer.d(integer);
diff --git a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java diff --git a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
index 85140d961722e86abfe7006a0ad752751e73c721..c7c191b0a9889450fdf495f5aa45d59f159f1401 100644 index 85140d961722e86abfe7006a0ad752751e73c721..e96fa348a37a39c381b6659f612232933686c2a7 100644
--- a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java --- a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
+++ b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java +++ b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
@@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
@ -1038,7 +1038,15 @@ index 85140d961722e86abfe7006a0ad752751e73c721..c7c191b0a9889450fdf495f5aa45d59f
gsonbuilder.registerTypeHierarchyAdapter(IChatBaseComponent.class, new IChatBaseComponent.ChatSerializer()); gsonbuilder.registerTypeHierarchyAdapter(IChatBaseComponent.class, new IChatBaseComponent.ChatSerializer());
gsonbuilder.registerTypeHierarchyAdapter(ChatModifier.class, new ChatModifier.ChatModifierSerializer()); gsonbuilder.registerTypeHierarchyAdapter(ChatModifier.class, new ChatModifier.ChatModifierSerializer());
gsonbuilder.registerTypeAdapterFactory(new ChatTypeAdapterFactory()); gsonbuilder.registerTypeAdapterFactory(new ChatTypeAdapterFactory());
@@ -351,10 +353,12 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC @@ -263,6 +265,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
}
public JsonElement serialize(IChatBaseComponent ichatbasecomponent, Type type, JsonSerializationContext jsonserializationcontext) {
+ if (ichatbasecomponent instanceof AdventureComponent) return jsonserializationcontext.serialize(ichatbasecomponent); // Paper
JsonObject jsonobject = new JsonObject();
if (!ichatbasecomponent.getChatModifier().g()) {
@@ -351,10 +354,12 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
return jsonobject; return jsonobject;
} }
@ -1051,7 +1059,7 @@ index 85140d961722e86abfe7006a0ad752751e73c721..c7c191b0a9889450fdf495f5aa45d59f
public static JsonElement b(IChatBaseComponent ichatbasecomponent) { public static JsonElement b(IChatBaseComponent ichatbasecomponent) {
return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent); return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent);
} }
@@ -364,6 +368,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC @@ -364,6 +369,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
return (IChatMutableComponent) ChatDeserializer.a(IChatBaseComponent.ChatSerializer.a, s, IChatMutableComponent.class, false); return (IChatMutableComponent) ChatDeserializer.a(IChatBaseComponent.ChatSerializer.a, s, IChatMutableComponent.class, false);
} }

View File

@ -21,10 +21,10 @@ index 5f1c5dd7902f6cff5acae05e8c6bf58a1ba5bdf1..df459918c14589155a574730205cb35d
public PacketDataSerializer a(IChatBaseComponent ichatbasecomponent) { public PacketDataSerializer a(IChatBaseComponent ichatbasecomponent) {
diff --git a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java diff --git a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
index c7c191b0a9889450fdf495f5aa45d59f159f1401..e0fe2ba95bd3cb6afcf9c804007438a513c095b7 100644 index e96fa348a37a39c381b6659f612232933686c2a7..a002125e454f8a86924e9010e0b20a95742fa04b 100644
--- a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java --- a/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
+++ b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java +++ b/src/main/java/net/minecraft/network/chat/IChatBaseComponent.java
@@ -363,6 +363,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC @@ -364,6 +364,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent); return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent);
} }