13
0
geforkt von Mirrors/Velocity

Fix title and system chat packets

Dieser Commit ist enthalten in:
Gero 2023-12-07 13:41:16 +01:00 committet von Shane Freeder
Ursprung eaa83378d7
Commit 519bf5ee04
11 geänderte Dateien mit 52 neuen und 48 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@ package com.velocitypowered.proxy.connection.backend;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.event.player.ServerResourcePackSendEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection;
@ -81,8 +82,11 @@ public class ConfigSessionHandler implements MinecraftSessionHandler {
@Override
public void activated() {
resourcePackToApply = serverConn.getPlayer().getAppliedResourcePack();
serverConn.getPlayer().clearAppliedResourcePack();
ConnectedPlayer player = serverConn.getPlayer();
if (player.getProtocolVersion() == ProtocolVersion.MINECRAFT_1_20_2) {
resourcePackToApply = player.getAppliedResourcePack();
}
player.clearAppliedResourcePack();
}
@Override

Datei anzeigen

@ -57,7 +57,6 @@ import com.velocitypowered.proxy.connection.player.VelocityResourcePackInfo;
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.connection.util.VelocityInboundConnection;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
@ -104,7 +103,6 @@ import net.kyori.adventure.platform.facet.FacetPointers.Type;
import net.kyori.adventure.pointer.Pointers;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.title.Title.Times;
@ -378,8 +376,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
// Use the title packet instead.
GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_ACTION_BAR, playerVersion);
pkt.setComponent(ProtocolUtils.getJsonChatSerializer(playerVersion)
.serialize(translated));
pkt.setComponent(new ComponentHolder(playerVersion, translated));
connection.write(pkt);
} else {
// Due to issues with action bar packets, we'll need to convert the text message into a
@ -428,8 +425,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override
public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
.getProtocolVersion());
GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion());
net.kyori.adventure.title.Title.Times times = title.times();
@ -442,12 +437,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
GenericTitlePacket subtitlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_SUBTITLE, this.getProtocolVersion());
subtitlePkt.setComponent(serializer.serialize(translateMessage(title.subtitle())));
subtitlePkt.setComponent(new ComponentHolder(
this.getProtocolVersion(), translateMessage(title.subtitle())));
connection.delayedWrite(subtitlePkt);
GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TITLE, this.getProtocolVersion());
titlePkt.setComponent(serializer.serialize(translateMessage(title.title())));
titlePkt.setComponent(new ComponentHolder(
this.getProtocolVersion(), translateMessage(title.title())));
connection.delayedWrite(titlePkt);
connection.flush();
@ -467,18 +464,17 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
return;
}
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
.getProtocolVersion());
if (part == TitlePart.TITLE) {
GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TITLE, this.getProtocolVersion());
titlePkt.setComponent(serializer.serialize(translateMessage((Component) value)));
titlePkt.setComponent(new ComponentHolder(
this.getProtocolVersion(), translateMessage((Component) value)));
connection.write(titlePkt);
} else if (part == TitlePart.SUBTITLE) {
GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_SUBTITLE, this.getProtocolVersion());
titlePkt.setComponent(serializer.serialize(translateMessage((Component) value)));
titlePkt.setComponent(new ComponentHolder(
this.getProtocolVersion(), translateMessage((Component) value)));
connection.write(titlePkt);
} else if (part == TitlePart.TIMES) {
Times times = (Times) value;

Datei anzeigen

@ -19,6 +19,7 @@ package com.velocitypowered.proxy.connection.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -118,6 +119,7 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo {
public BuilderImpl(String url) {
this.url = Preconditions.checkNotNull(url, "url");
this.id = UUID.nameUUIDFromBytes(url.getBytes(StandardCharsets.UTF_8));
}
@Override

Datei anzeigen

@ -22,44 +22,39 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component;
public class SystemChat implements MinecraftPacket {
public SystemChat() {
}
public SystemChat(Component component, ChatType type) {
public SystemChat(ComponentHolder component, ChatType type) {
this.component = component;
this.type = type;
}
private Component component;
private ComponentHolder component;
private ChatType type;
public ChatType getType() {
return type;
}
public Component getComponent() {
public ComponentHolder getComponent() {
return component;
}
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction,
ProtocolVersion protocolVersion) {
component = ProtocolUtils.getJsonChatSerializer(protocolVersion)
.deserialize(ProtocolUtils.readString(buf));
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
component = ComponentHolder.read(buf, version);
// System chat is never decoded so this doesn't matter for now
type = ChatType.values()[ProtocolUtils.readVarInt(buf)];
}
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction,
ProtocolVersion protocolVersion) {
ProtocolUtils.writeString(buf,
ProtocolUtils.getJsonChatSerializer(protocolVersion).serialize(component));
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
component.write(buf);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
switch (type) {
case SYSTEM:
buf.writeBoolean(false);

Datei anzeigen

@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ChatType;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import com.velocitypowered.proxy.protocol.packet.chat.SystemChat;
import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderV2;
import net.kyori.adventure.text.Component;
@ -35,7 +36,7 @@ public class KeyedChatBuilder extends ChatBuilderV2 {
public MinecraftPacket toClient() {
// This is temporary
Component msg = component == null ? Component.text(message) : component;
return new SystemChat(msg, type == ChatType.CHAT ? ChatType.SYSTEM : type);
return new SystemChat(new ComponentHolder(version, msg), type == ChatType.CHAT ? ChatType.SYSTEM : type);
}
@Override

Datei anzeigen

@ -20,6 +20,7 @@ package com.velocitypowered.proxy.protocol.packet.chat.session;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ChatType;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import com.velocitypowered.proxy.protocol.packet.chat.LastSeenMessages;
import com.velocitypowered.proxy.protocol.packet.chat.SystemChat;
import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderV2;
@ -35,7 +36,7 @@ public class SessionChatBuilder extends ChatBuilderV2 {
public MinecraftPacket toClient() {
// This is temporary
Component msg = component == null ? Component.text(message) : component;
return new SystemChat(msg, type == ChatType.CHAT ? ChatType.SYSTEM : type);
return new SystemChat(new ComponentHolder(version, msg), type == ChatType.CHAT ? ChatType.SYSTEM : type);
}
@Override

Datei anzeigen

@ -20,6 +20,7 @@ package com.velocitypowered.proxy.protocol.packet.title;
import com.velocitypowered.api.network.ProtocolVersion;
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;
public abstract class GenericTitlePacket implements MinecraftPacket {
@ -55,11 +56,11 @@ public abstract class GenericTitlePacket implements MinecraftPacket {
return action;
}
public String getComponent() {
public ComponentHolder getComponent() {
throw new UnsupportedOperationException("Invalid function for this TitlePacket ActionType");
}
public void setComponent(String component) {
public void setComponent(ComponentHolder component) {
throw new UnsupportedOperationException("Invalid function for this TitlePacket ActionType");
}

Datei anzeigen

@ -20,12 +20,13 @@ package com.velocitypowered.proxy.protocol.packet.title;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class LegacyTitlePacket extends GenericTitlePacket {
private @Nullable String component;
private @Nullable ComponentHolder component;
private int fadeIn;
private int stay;
private int fadeOut;
@ -45,7 +46,7 @@ public class LegacyTitlePacket extends GenericTitlePacket {
if (component == null) {
throw new IllegalStateException("No component found for " + getAction());
}
ProtocolUtils.writeString(buf, component);
component.write(buf);
break;
case SET_TIMES:
buf.writeInt(fadeIn);
@ -67,12 +68,12 @@ public class LegacyTitlePacket extends GenericTitlePacket {
}
@Override
public @Nullable String getComponent() {
public @Nullable ComponentHolder getComponent() {
return component;
}
@Override
public void setComponent(@Nullable String component) {
public void setComponent(@Nullable ComponentHolder component) {
this.component = component;
}

Datei anzeigen

@ -20,11 +20,12 @@ package com.velocitypowered.proxy.protocol.packet.title;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf;
public class TitleActionbarPacket extends GenericTitlePacket {
private String component;
private ComponentHolder component;
public TitleActionbarPacket() {
setAction(ActionType.SET_TITLE);
@ -32,16 +33,16 @@ public class TitleActionbarPacket extends GenericTitlePacket {
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, component);
component.write(buf);
}
@Override
public String getComponent() {
public ComponentHolder getComponent() {
return component;
}
@Override
public void setComponent(String component) {
public void setComponent(ComponentHolder component) {
this.component = component;
}

Datei anzeigen

@ -20,11 +20,12 @@ package com.velocitypowered.proxy.protocol.packet.title;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf;
public class TitleSubtitlePacket extends GenericTitlePacket {
private String component;
private ComponentHolder component;
public TitleSubtitlePacket() {
setAction(ActionType.SET_SUBTITLE);
@ -32,16 +33,16 @@ public class TitleSubtitlePacket extends GenericTitlePacket {
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, component);
component.write(buf);
}
@Override
public String getComponent() {
public ComponentHolder getComponent() {
return component;
}
@Override
public void setComponent(String component) {
public void setComponent(ComponentHolder component) {
this.component = component;
}

Datei anzeigen

@ -20,11 +20,12 @@ package com.velocitypowered.proxy.protocol.packet.title;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf;
public class TitleTextPacket extends GenericTitlePacket {
private String component;
private ComponentHolder component;
public TitleTextPacket() {
setAction(ActionType.SET_TITLE);
@ -32,16 +33,16 @@ public class TitleTextPacket extends GenericTitlePacket {
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, component);
component.write(buf);
}
@Override
public String getComponent() {
public ComponentHolder getComponent() {
return component;
}
@Override
public void setComponent(String component) {
public void setComponent(ComponentHolder component) {
this.component = component;
}