From b00d3bcf5b4b9eb351059dce923eb5a9e8b4ead5 Mon Sep 17 00:00:00 2001 From: Gero Date: Thu, 7 Dec 2023 19:19:33 +0100 Subject: [PATCH] Fix TabCompleteResponse --- .../connection/client/ClientPlaySessionHandler.java | 11 +++++++---- .../proxy/protocol/packet/TabCompleteResponse.java | 13 +++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index e9a3211f5..08da36ab5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -53,6 +53,7 @@ import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse.Offer; import com.velocitypowered.proxy.protocol.packet.chat.ChatHandler; import com.velocitypowered.proxy.protocol.packet.chat.ChatTimeKeeper; import com.velocitypowered.proxy.protocol.packet.chat.CommandHandler; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedChatHandler; import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedCommandHandler; import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedPlayerChat; @@ -631,10 +632,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { List offers = new ArrayList<>(); for (Suggestion suggestion : suggestions.getList()) { String offer = suggestion.getText(); - Component tooltip = null; + ComponentHolder tooltip = null; if (suggestion.getTooltip() != null && suggestion.getTooltip() instanceof VelocityBrigadierMessage) { - tooltip = ((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent(); + tooltip = new ComponentHolder(player.getProtocolVersion(), + ((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent()); } offers.add(new Offer(offer, tooltip)); } @@ -696,10 +698,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { if (legacy && offer.startsWith(command)) { offer = offer.substring(command.length()); } - Component tooltip = null; + ComponentHolder tooltip = null; if (suggestion.getTooltip() != null && suggestion.getTooltip() instanceof VelocityBrigadierMessage) { - tooltip = ((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent(); + tooltip = new ComponentHolder(player.getProtocolVersion(), + ((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent()); } response.getOffers().add(new Offer(offer, tooltip)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java index 835c39a00..f6a3aabbb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java @@ -24,10 +24,10 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; -import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; public class TabCompleteResponse implements MinecraftPacket { @@ -84,8 +84,7 @@ public class TabCompleteResponse implements MinecraftPacket { int offersAvailable = ProtocolUtils.readVarInt(buf); for (int i = 0; i < offersAvailable; i++) { String offer = ProtocolUtils.readString(buf); - Component tooltip = buf.readBoolean() ? ProtocolUtils.getJsonChatSerializer(version) - .deserialize(ProtocolUtils.readString(buf)) : null; + ComponentHolder tooltip = buf.readBoolean() ? ComponentHolder.read(buf, version) : null; offers.add(new Offer(offer, tooltip)); } } else { @@ -107,8 +106,7 @@ public class TabCompleteResponse implements MinecraftPacket { ProtocolUtils.writeString(buf, offer.text); buf.writeBoolean(offer.tooltip != null); if (offer.tooltip != null) { - ProtocolUtils.writeString(buf, ProtocolUtils.getJsonChatSerializer(version) - .serialize(offer.tooltip)); + offer.tooltip.write(buf); } } } else { @@ -127,14 +125,13 @@ public class TabCompleteResponse implements MinecraftPacket { public static class Offer implements Comparable { private final String text; - private final @Nullable Component tooltip; + private final @Nullable ComponentHolder tooltip; public Offer(String text) { this(text, null); } - public Offer(String text, - @Nullable Component tooltip) { + public Offer(String text, @Nullable ComponentHolder tooltip) { this.text = text; this.tooltip = tooltip; }