From fcef6238476c1f33155bc09fd4c8f4cbe18ebff8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 23 Oct 2018 13:06:54 -0400 Subject: [PATCH] Respect server protocol version when writing packets to the server. Needed for ViaVersion. --- .../proxy/connection/client/ClientPlaySessionHandler.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 1a0777187..c7bf9c6c2 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 @@ -135,7 +135,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } if (actuallyRegistered.size() > 0) { - PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(player.getProtocolVersion(), actuallyRegistered); + PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(player.getConnectedServer() + .getConnection().getProtocolVersion(), actuallyRegistered); player.getConnectedServer().getConnection().write(newRegisterPacket); } } else if (PluginMessageUtil.isMCUnregister(packet)) { @@ -271,15 +272,16 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { serverBossBars.clear(); // Tell the server about this client's plugin message channels. + int serverVersion = player.getConnectedServer().getConnection().getProtocolVersion(); Collection toRegister = new HashSet<>(clientPluginMsgChannels); - if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) { + if (serverVersion >= ProtocolConstants.MINECRAFT_1_13) { toRegister.addAll(server.getChannelRegistrar().getModernChannelIds()); } else { toRegister.addAll(server.getChannelRegistrar().getIdsForLegacyConnections()); } if (!toRegister.isEmpty()) { player.getConnectedServer().getConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket( - player.getConnection().getProtocolVersion(), toRegister)); + serverVersion, toRegister)); } // If we had plugin messages queued during login/FML handshake, send them now.