13
0
geforkt von Mirrors/Velocity

Fix TabCompleteResponse

Dieser Commit ist enthalten in:
Gero 2023-12-07 19:19:33 +01:00 committet von Shane Freeder
Ursprung 32228e85ab
Commit b00d3bcf5b
2 geänderte Dateien mit 12 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -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.ChatHandler;
import com.velocitypowered.proxy.protocol.packet.chat.ChatTimeKeeper; import com.velocitypowered.proxy.protocol.packet.chat.ChatTimeKeeper;
import com.velocitypowered.proxy.protocol.packet.chat.CommandHandler; 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.KeyedChatHandler;
import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedCommandHandler; import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedCommandHandler;
import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedPlayerChat; import com.velocitypowered.proxy.protocol.packet.chat.keyed.KeyedPlayerChat;
@ -631,10 +632,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
List<Offer> offers = new ArrayList<>(); List<Offer> offers = new ArrayList<>();
for (Suggestion suggestion : suggestions.getList()) { for (Suggestion suggestion : suggestions.getList()) {
String offer = suggestion.getText(); String offer = suggestion.getText();
Component tooltip = null; ComponentHolder tooltip = null;
if (suggestion.getTooltip() != null if (suggestion.getTooltip() != null
&& suggestion.getTooltip() instanceof VelocityBrigadierMessage) { && suggestion.getTooltip() instanceof VelocityBrigadierMessage) {
tooltip = ((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent(); tooltip = new ComponentHolder(player.getProtocolVersion(),
((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent());
} }
offers.add(new Offer(offer, tooltip)); offers.add(new Offer(offer, tooltip));
} }
@ -696,10 +698,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (legacy && offer.startsWith(command)) { if (legacy && offer.startsWith(command)) {
offer = offer.substring(command.length()); offer = offer.substring(command.length());
} }
Component tooltip = null; ComponentHolder tooltip = null;
if (suggestion.getTooltip() != null if (suggestion.getTooltip() != null
&& suggestion.getTooltip() instanceof VelocityBrigadierMessage) { && 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)); response.getOffers().add(new Offer(offer, tooltip));
} }

Datei anzeigen

@ -24,10 +24,10 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class TabCompleteResponse implements MinecraftPacket { public class TabCompleteResponse implements MinecraftPacket {
@ -84,8 +84,7 @@ public class TabCompleteResponse implements MinecraftPacket {
int offersAvailable = ProtocolUtils.readVarInt(buf); int offersAvailable = ProtocolUtils.readVarInt(buf);
for (int i = 0; i < offersAvailable; i++) { for (int i = 0; i < offersAvailable; i++) {
String offer = ProtocolUtils.readString(buf); String offer = ProtocolUtils.readString(buf);
Component tooltip = buf.readBoolean() ? ProtocolUtils.getJsonChatSerializer(version) ComponentHolder tooltip = buf.readBoolean() ? ComponentHolder.read(buf, version) : null;
.deserialize(ProtocolUtils.readString(buf)) : null;
offers.add(new Offer(offer, tooltip)); offers.add(new Offer(offer, tooltip));
} }
} else { } else {
@ -107,8 +106,7 @@ public class TabCompleteResponse implements MinecraftPacket {
ProtocolUtils.writeString(buf, offer.text); ProtocolUtils.writeString(buf, offer.text);
buf.writeBoolean(offer.tooltip != null); buf.writeBoolean(offer.tooltip != null);
if (offer.tooltip != null) { if (offer.tooltip != null) {
ProtocolUtils.writeString(buf, ProtocolUtils.getJsonChatSerializer(version) offer.tooltip.write(buf);
.serialize(offer.tooltip));
} }
} }
} else { } else {
@ -127,14 +125,13 @@ public class TabCompleteResponse implements MinecraftPacket {
public static class Offer implements Comparable<Offer> { public static class Offer implements Comparable<Offer> {
private final String text; private final String text;
private final @Nullable Component tooltip; private final @Nullable ComponentHolder tooltip;
public Offer(String text) { public Offer(String text) {
this(text, null); this(text, null);
} }
public Offer(String text, public Offer(String text, @Nullable ComponentHolder tooltip) {
@Nullable Component tooltip) {
this.text = text; this.text = text;
this.tooltip = tooltip; this.tooltip = tooltip;
} }