From a3437ca6ba821c266396d89c01ab1cfbb6417efd Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:36:46 +0200 Subject: [PATCH] Fix 1.19 -> 1.18.2 player info display name translation: Empty text edge case (#3146) --- .../Protocol1_19To1_18_2.java | 7 +++++-- .../packets/EntityPackets.java | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java index 5731d52da..7e7ebd4e1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java @@ -64,6 +64,10 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol { final JsonElement component = wrapper.read(Type.COMPONENT); - final boolean isEmpty = component.isJsonNull() || (component.isJsonArray() && component.getAsJsonArray().size() == 0); - if (!isEmpty) { + if (!isTextComponentNull(component)) { wrapper.write(Type.COMPONENT, component); } else { wrapper.write(Type.COMPONENT, GsonComponentSerializer.gson().serializeToTree(Component.empty())); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index 0ea443037..5d44eeea8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.collect.Maps; +import com.google.gson.JsonElement; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.data.entity.DimensionData; import com.viaversion.viaversion.api.minecraft.Position; @@ -280,19 +281,29 @@ public final class EntityPackets extends EntityRewriter { for (int j = 0; j < properties; j++) { wrapper.passthrough(Type.STRING); // Name wrapper.passthrough(Type.STRING); // Value - wrapper.passthrough(Type.OPTIONAL_STRING); // Signature + wrapper.passthrough(Type.OPTIONAL_STRING); // Signature } wrapper.passthrough(Type.VAR_INT); // Gamemode wrapper.passthrough(Type.VAR_INT); // Ping - wrapper.passthrough(Type.OPTIONAL_COMPONENT); // Display name + final JsonElement displayName = wrapper.read(Type.OPTIONAL_COMPONENT); // Display name + if (!Protocol1_19To1_18_2.isTextComponentNull(displayName)) { + wrapper.write(Type.OPTIONAL_COMPONENT, displayName); + } else { + wrapper.write(Type.OPTIONAL_COMPONENT, null); + } // No public profile signature wrapper.write(Type.OPTIONAL_PROFILE_KEY, null); } else if (action == 1 || action == 2) { // Update gamemode/update latency wrapper.passthrough(Type.VAR_INT); } else if (action == 3) { // Update display name - wrapper.passthrough(Type.OPTIONAL_COMPONENT); + final JsonElement displayName = wrapper.read(Type.OPTIONAL_COMPONENT); // Display name + if (!Protocol1_19To1_18_2.isTextComponentNull(displayName)) { + wrapper.write(Type.OPTIONAL_COMPONENT, displayName); + } else { + wrapper.write(Type.OPTIONAL_COMPONENT, null); + } } } });