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.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.event.player.ServerResourcePackSendEvent; import com.velocitypowered.api.event.player.ServerResourcePackSendEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.ResourcePackInfo; import com.velocitypowered.api.proxy.player.ResourcePackInfo;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
@ -81,8 +82,11 @@ public class ConfigSessionHandler implements MinecraftSessionHandler {
@Override @Override
public void activated() { public void activated() {
resourcePackToApply = serverConn.getPlayer().getAppliedResourcePack(); ConnectedPlayer player = serverConn.getPlayer();
serverConn.getPlayer().clearAppliedResourcePack(); if (player.getProtocolVersion() == ProtocolVersion.MINECRAFT_1_20_2) {
resourcePackToApply = player.getAppliedResourcePack();
}
player.clearAppliedResourcePack();
} }
@Override @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.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.connection.util.VelocityInboundConnection; import com.velocitypowered.proxy.connection.util.VelocityInboundConnection;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; 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.pointer.Pointers;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; 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.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.title.Title.Times; import net.kyori.adventure.title.Title.Times;
@ -378,8 +376,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
// Use the title packet instead. // Use the title packet instead.
GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_ACTION_BAR, playerVersion); GenericTitlePacket.ActionType.SET_ACTION_BAR, playerVersion);
pkt.setComponent(ProtocolUtils.getJsonChatSerializer(playerVersion) pkt.setComponent(new ComponentHolder(playerVersion, translated));
.serialize(translated));
connection.write(pkt); connection.write(pkt);
} else { } else {
// Due to issues with action bar packets, we'll need to convert the text message into a // 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 @Override
public void showTitle(net.kyori.adventure.title.@NonNull Title title) { public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
.getProtocolVersion());
GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion()); GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion());
net.kyori.adventure.title.Title.Times times = title.times(); net.kyori.adventure.title.Title.Times times = title.times();
@ -442,12 +437,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
GenericTitlePacket subtitlePkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket subtitlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_SUBTITLE, this.getProtocolVersion()); 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); connection.delayedWrite(subtitlePkt);
GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TITLE, this.getProtocolVersion()); 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.delayedWrite(titlePkt);
connection.flush(); connection.flush();
@ -467,18 +464,17 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
return; return;
} }
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
.getProtocolVersion());
if (part == TitlePart.TITLE) { if (part == TitlePart.TITLE) {
GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TITLE, this.getProtocolVersion()); 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); connection.write(titlePkt);
} else if (part == TitlePart.SUBTITLE) { } else if (part == TitlePart.SUBTITLE) {
GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_SUBTITLE, this.getProtocolVersion()); 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); connection.write(titlePkt);
} else if (part == TitlePart.TIMES) { } else if (part == TitlePart.TIMES) {
Times times = (Times) value; Times times = (Times) value;

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ChatType; 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.SystemChat;
import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderV2; import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderV2;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -35,7 +36,7 @@ public class KeyedChatBuilder extends ChatBuilderV2 {
public MinecraftPacket toClient() { public MinecraftPacket toClient() {
// This is temporary // This is temporary
Component msg = component == null ? Component.text(message) : component; 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 @Override

Datei anzeigen

@ -20,6 +20,7 @@ package com.velocitypowered.proxy.protocol.packet.chat.session;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ChatType; 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.LastSeenMessages;
import com.velocitypowered.proxy.protocol.packet.chat.SystemChat; import com.velocitypowered.proxy.protocol.packet.chat.SystemChat;
import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderV2; import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderV2;
@ -35,7 +36,7 @@ public class SessionChatBuilder extends ChatBuilderV2 {
public MinecraftPacket toClient() { public MinecraftPacket toClient() {
// This is temporary // This is temporary
Component msg = component == null ? Component.text(message) : component; 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 @Override

Datei anzeigen

@ -20,6 +20,7 @@ package com.velocitypowered.proxy.protocol.packet.title;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
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;
public abstract class GenericTitlePacket implements MinecraftPacket { public abstract class GenericTitlePacket implements MinecraftPacket {
@ -55,11 +56,11 @@ public abstract class GenericTitlePacket implements MinecraftPacket {
return action; return action;
} }
public String getComponent() { public ComponentHolder getComponent() {
throw new UnsupportedOperationException("Invalid function for this TitlePacket ActionType"); 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"); 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.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
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 org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class LegacyTitlePacket extends GenericTitlePacket { public class LegacyTitlePacket extends GenericTitlePacket {
private @Nullable String component; private @Nullable ComponentHolder component;
private int fadeIn; private int fadeIn;
private int stay; private int stay;
private int fadeOut; private int fadeOut;
@ -45,7 +46,7 @@ public class LegacyTitlePacket extends GenericTitlePacket {
if (component == null) { if (component == null) {
throw new IllegalStateException("No component found for " + getAction()); throw new IllegalStateException("No component found for " + getAction());
} }
ProtocolUtils.writeString(buf, component); component.write(buf);
break; break;
case SET_TIMES: case SET_TIMES:
buf.writeInt(fadeIn); buf.writeInt(fadeIn);
@ -67,12 +68,12 @@ public class LegacyTitlePacket extends GenericTitlePacket {
} }
@Override @Override
public @Nullable String getComponent() { public @Nullable ComponentHolder getComponent() {
return component; return component;
} }
@Override @Override
public void setComponent(@Nullable String component) { public void setComponent(@Nullable ComponentHolder component) {
this.component = 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.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
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;
public class TitleActionbarPacket extends GenericTitlePacket { public class TitleActionbarPacket extends GenericTitlePacket {
private String component; private ComponentHolder component;
public TitleActionbarPacket() { public TitleActionbarPacket() {
setAction(ActionType.SET_TITLE); setAction(ActionType.SET_TITLE);
@ -32,16 +33,16 @@ public class TitleActionbarPacket extends GenericTitlePacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, component); component.write(buf);
} }
@Override @Override
public String getComponent() { public ComponentHolder getComponent() {
return component; return component;
} }
@Override @Override
public void setComponent(String component) { public void setComponent(ComponentHolder component) {
this.component = 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.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
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;
public class TitleSubtitlePacket extends GenericTitlePacket { public class TitleSubtitlePacket extends GenericTitlePacket {
private String component; private ComponentHolder component;
public TitleSubtitlePacket() { public TitleSubtitlePacket() {
setAction(ActionType.SET_SUBTITLE); setAction(ActionType.SET_SUBTITLE);
@ -32,16 +33,16 @@ public class TitleSubtitlePacket extends GenericTitlePacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, component); component.write(buf);
} }
@Override @Override
public String getComponent() { public ComponentHolder getComponent() {
return component; return component;
} }
@Override @Override
public void setComponent(String component) { public void setComponent(ComponentHolder component) {
this.component = 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.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
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;
public class TitleTextPacket extends GenericTitlePacket { public class TitleTextPacket extends GenericTitlePacket {
private String component; private ComponentHolder component;
public TitleTextPacket() { public TitleTextPacket() {
setAction(ActionType.SET_TITLE); setAction(ActionType.SET_TITLE);
@ -32,16 +33,16 @@ public class TitleTextPacket extends GenericTitlePacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, component); component.write(buf);
} }
@Override @Override
public String getComponent() { public ComponentHolder getComponent() {
return component; return component;
} }
@Override @Override
public void setComponent(String component) { public void setComponent(ComponentHolder component) {
this.component = component; this.component = component;
} }