mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-26 03:55:28 +01:00
Fix 1.19 -> 1.18.2 player info display name translation: Empty text edge case (#3146)
This commit is contained in:
parent
e3dc9e5b66
commit
a3437ca6ba
@ -64,6 +64,10 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
|
||||
super(ClientboundPackets1_18.class, ClientboundPackets1_19.class, ServerboundPackets1_17.class, ServerboundPackets1_19.class);
|
||||
}
|
||||
|
||||
public static boolean isTextComponentNull(final JsonElement element) {
|
||||
return element == null || element.isJsonNull() || (element.isJsonArray() && element.getAsJsonArray().size() == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
final TagRewriter tagRewriter = new TagRewriter(this);
|
||||
@ -120,8 +124,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
|
||||
|
||||
final PacketHandler titleHandler = wrapper -> {
|
||||
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()));
|
||||
|
@ -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;
|
||||
@ -285,14 +286,24 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user