3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Fix 1.19 -> 1.18.2 player info display name translation: Empty text edge case (#3146)

Dieser Commit ist enthalten in:
RK_01 2022-10-27 10:36:46 +02:00 committet von GitHub
Ursprung e3dc9e5b66
Commit a3437ca6ba
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 19 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -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()));

Datei anzeigen

@ -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<Protocol1_19To1_18_2> {
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);
}
}
}
});