From 5822cc31d8dbb1dd4af41c200690956308f66c91 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Nov 2018 17:03:31 -0500 Subject: [PATCH] If we failed to unregister, don't fire the disconnect event --- .../java/com/velocitypowered/proxy/VelocityServer.java | 7 ++++--- .../proxy/connection/client/ConnectedPlayer.java | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 52a850e53..e0f250f9a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -291,9 +291,10 @@ public class VelocityServer implements ProxyServer { return true; } - public void unregisterConnection(ConnectedPlayer connection) { - connectionsByName.remove(connection.getUsername().toLowerCase(Locale.US), connection); - connectionsByUuid.remove(connection.getUniqueId(), connection); + public boolean unregisterConnection(ConnectedPlayer connection) { + boolean name = connectionsByName.remove(connection.getUsername().toLowerCase(Locale.US), connection); + boolean uuid = connectionsByUuid.remove(connection.getUniqueId(), connection); + return name && uuid; } @Override 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 e06cdacfa..d76070057 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 @@ -432,8 +432,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { if (connectedServer != null) { connectedServer.disconnect(); } - server.unregisterConnection(this); - server.getEventManager().fireAndForget(new DisconnectEvent(this)); + if (server.unregisterConnection(this)) { + server.getEventManager().fireAndForget(new DisconnectEvent(this)); + } } @Override