From d0b49009e5b45e39d210d4fda97e732dba3f3097 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 4 Sep 2024 20:27:38 +0200 Subject: [PATCH] Rewrite display name component in player info packet in 1.20.3->.5 (#4136) --- .../Protocol1_20_3To1_20_5.java | 1 + .../rewriter/ComponentRewriter.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java index 75e4c4ccd..89e92006c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java @@ -103,6 +103,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol { diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java index 9428917a4..5aa31652b 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java @@ -40,6 +40,7 @@ import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.TagUtil; import org.checkerframework.checker.nullness.qual.Nullable; +import java.util.BitSet; /** * Handles json and tag components, containing methods to override certain parts of the handling. @@ -139,6 +140,43 @@ public class ComponentRewriter implements com.v }); } + public void registerPlayerInfoUpdate1_20_3(final C packetType) { + protocol.registerClientbound(packetType, wrapper -> { + final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM); + if (!actions.get(5)) { // Update display name + return; + } + final int entries = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < entries; i++) { + wrapper.passthrough(Types.UUID); + if (actions.get(0)) { + wrapper.passthrough(Types.STRING); // Player Name + + final int properties = wrapper.passthrough(Types.VAR_INT); + for (int j = 0; j < properties; j++) { + wrapper.passthrough(Types.STRING); // Name + wrapper.passthrough(Types.STRING); // Value + wrapper.passthrough(Types.OPTIONAL_STRING); // Signature + } + } + if (actions.get(1) && wrapper.passthrough(Types.BOOLEAN)) { + wrapper.passthrough(Types.UUID); // Session UUID + wrapper.passthrough(Types.PROFILE_KEY); + } + if (actions.get(2)) { + wrapper.passthrough(Types.VAR_INT); // Gamemode + } + if (actions.get(3)) { + wrapper.passthrough(Types.BOOLEAN); // Listed + } + if (actions.get(4)) { + wrapper.passthrough(Types.VAR_INT); // Latency + } + processTag(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_TAG)); + } + }); + } + public void registerPlayerCombatKill(final C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override