From 5a26b4e03d887e0cf419b504d541df52c54f5920 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 30 Aug 2020 20:58:15 -0400 Subject: [PATCH] Fix coding error that caused players to time out if moving to another server fails Thanks to @Gabik21 for noticing this bug. --- .../proxy/connection/client/ConnectedPlayer.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 596c36c3c..c97e492c4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -573,16 +573,21 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, !kickedFromCurrent, result); - handleKickEvent(originalEvent, friendlyReason); + handleKickEvent(originalEvent, friendlyReason, kickedFromCurrent); } - private void handleKickEvent(KickedFromServerEvent originalEvent, Component friendlyReason) { + private void handleKickEvent(KickedFromServerEvent originalEvent, Component friendlyReason, + boolean kickedFromCurrent) { server.getEventManager().fire(originalEvent) .thenAcceptAsync(event -> { // There can't be any connection in flight now. connectionInFlight = null; + // Make sure we clear the current connected server as the connection is invalid. - connectedServer = null; + boolean previouslyConnected = connectedServer != null; + if (kickedFromCurrent) { + connectedServer = null; + } if (!isActive()) { // If the connection is no longer active, it makes no sense to try and recover it. @@ -628,7 +633,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { }, connection.eventLoop()); } else if (event.getResult() instanceof Notify) { Notify res = (Notify) event.getResult(); - if (event.kickedDuringServerConnect()) { + if (event.kickedDuringServerConnect() && previouslyConnected) { sendMessage(res.getMessageComponent()); } else { disconnect(res.getMessageComponent());