From 8a6c20ee32f365c802788fd5836c45b89b536556 Mon Sep 17 00:00:00 2001 From: Gero Date: Thu, 7 Dec 2023 16:20:32 +0100 Subject: [PATCH] Fix NPE in ComponentHolder --- .../proxy/connection/client/ConnectedPlayer.java | 2 +- .../proxy/protocol/packet/HeaderAndFooter.java | 9 ++++----- .../proxy/protocol/packet/chat/ComponentHolder.java | 6 ------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 6d8fb1828..99f4ba608 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -543,7 +543,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, public void clearPlayerListHeaderAndFooter() { clearPlayerListHeaderAndFooterSilent(); if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { - this.connection.write(HeaderAndFooter.reset()); + this.connection.write(HeaderAndFooter.reset(this.getProtocolVersion())); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java index 4ca819a13..e509dbe3c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java @@ -28,13 +28,11 @@ import net.kyori.adventure.text.Component; public class HeaderAndFooter implements MinecraftPacket { - private static final HeaderAndFooter RESET = new HeaderAndFooter(); - private final ComponentHolder header; private final ComponentHolder footer; public HeaderAndFooter() { - this(ComponentHolder.EMPTY, ComponentHolder.EMPTY); + throw new UnsupportedOperationException("Decode is not implemented"); } public HeaderAndFooter(ComponentHolder header, ComponentHolder footer) { @@ -72,7 +70,8 @@ public class HeaderAndFooter implements MinecraftPacket { new ComponentHolder(protocolVersion, footer)); } - public static HeaderAndFooter reset() { - return RESET; + public static HeaderAndFooter reset(ProtocolVersion version) { + ComponentHolder empty = new ComponentHolder(version, Component.empty()); + return new HeaderAndFooter(empty, empty); } } \ No newline at end of file diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/chat/ComponentHolder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/chat/ComponentHolder.java index 24367f9f6..debbb8348 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/chat/ComponentHolder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/chat/ComponentHolder.java @@ -52,14 +52,8 @@ import java.util.List; import java.util.Map; public class ComponentHolder { - public static ComponentHolder EMPTY = new ComponentHolder(null, Component.empty()); private static final Logger logger = LogManager.getLogger(ComponentHolder.class); - static { - EMPTY.json = "{\"text\":\"\"}"; - EMPTY.binaryTag = StringBinaryTag.stringBinaryTag(""); - } - private final ProtocolVersion version; private @MonotonicNonNull Component component; private @MonotonicNonNull String json;