From b34cfcde5a9256fd18e6979559d5c28b0d34b59d Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 28 Sep 2023 06:55:00 +1000 Subject: [PATCH] Simplify UpstreamBridge packet handling code --- .../net/md_5/bungee/connection/UpstreamBridge.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 26563db4..3c312589 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -10,6 +10,7 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.ServerConnection; import net.md_5.bungee.ServerConnection.KeepAliveData; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; @@ -134,14 +135,10 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(PacketWrapper packet) throws Exception { - if ( con.getServer() != null ) + ServerConnection server = con.getServer(); + if ( server != null && server.isConnected() ) { - if ( con.getServer().getCh().isClosed() ) - { - return; - } - - Protocol serverEncode = con.getServer().getCh().getEncodeProtocol(); + Protocol serverEncode = server.getCh().getEncodeProtocol(); // #3527: May still have old packets from client in game state when switching server to configuration state - discard those if ( packet.protocol != serverEncode ) { @@ -153,7 +150,7 @@ public class UpstreamBridge extends PacketHandler { rewrite.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() ); } - con.getServer().getCh().write( packet ); + server.getCh().write( packet ); } }