Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 17:10:13 +01:00
Fix 1.19 -> 1.18.2 player info display name translation: Empty text edge case (#3146)
Dieser Commit ist enthalten in:
Ursprung
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);
|
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
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
final TagRewriter tagRewriter = new TagRewriter(this);
|
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 PacketHandler titleHandler = wrapper -> {
|
||||||
final JsonElement component = wrapper.read(Type.COMPONENT);
|
final JsonElement component = wrapper.read(Type.COMPONENT);
|
||||||
final boolean isEmpty = component.isJsonNull() || (component.isJsonArray() && component.getAsJsonArray().size() == 0);
|
if (!isTextComponentNull(component)) {
|
||||||
if (!isEmpty) {
|
|
||||||
wrapper.write(Type.COMPONENT, component);
|
wrapper.write(Type.COMPONENT, component);
|
||||||
} else {
|
} else {
|
||||||
wrapper.write(Type.COMPONENT, GsonComponentSerializer.gson().serializeToTree(Component.empty()));
|
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.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.data.entity.DimensionData;
|
import com.viaversion.viaversion.api.data.entity.DimensionData;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
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); // Gamemode
|
||||||
wrapper.passthrough(Type.VAR_INT); // Ping
|
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
|
// No public profile signature
|
||||||
wrapper.write(Type.OPTIONAL_PROFILE_KEY, null);
|
wrapper.write(Type.OPTIONAL_PROFILE_KEY, null);
|
||||||
} else if (action == 1 || action == 2) { // Update gamemode/update latency
|
} else if (action == 1 || action == 2) { // Update gamemode/update latency
|
||||||
wrapper.passthrough(Type.VAR_INT);
|
wrapper.passthrough(Type.VAR_INT);
|
||||||
} else if (action == 3) { // Update display name
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren