From 1515c5069b1db628d55358a13a202fb848e9cdb5 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 21 Nov 2018 23:36:47 -0500 Subject: [PATCH] Fix up some stuff --- .../velocitypowered/proxy/VelocityServer.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 04248c702..3aea20f4e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -246,7 +246,8 @@ public class VelocityServer implements ProxyServer { return false; } - // Re-register servers. If we are replacing a server, we must evacuate players. + // Re-register servers. If a server is being replaced, make sure to note what players need to + // move back to a fallback server. Collection evacuate = new ArrayList<>(); for (Map.Entry entry : newConfiguration.getServers().entrySet()) { ServerInfo newInfo = @@ -267,29 +268,32 @@ public class VelocityServer implements ProxyServer { } } - CountDownLatch latch = new CountDownLatch(evacuate.size()); - for (ConnectedPlayer player : evacuate) { - Optional next = player.getNextServerToTry(); - if (next.isPresent()) { - player.createConnectionRequest(next.get()).connectWithIndication() - .whenComplete((success, ex) -> { - if (ex != null || success == null || !success) { - player.disconnect(TextComponent.of("Your server has been changed, but we could " - + "not move you to any fallback servers.")); - } - latch.countDown(); - }); - } else { - latch.countDown(); - player.disconnect(TextComponent.of("Your server has been changed, but we could " - + "not move you to any fallback servers.")); + // If we had any players to evacuate, let's move them now. Wait until they are all moved off. + if (!evacuate.isEmpty()) { + CountDownLatch latch = new CountDownLatch(evacuate.size()); + for (ConnectedPlayer player : evacuate) { + Optional next = player.getNextServerToTry(); + if (next.isPresent()) { + player.createConnectionRequest(next.get()).connectWithIndication() + .whenComplete((success, ex) -> { + if (ex != null || success == null || !success) { + player.disconnect(TextComponent.of("Your server has been changed, but we could " + + "not move you to any fallback servers.")); + } + latch.countDown(); + }); + } else { + latch.countDown(); + player.disconnect(TextComponent.of("Your server has been changed, but we could " + + "not move you to any fallback servers.")); + } + } + try { + latch.await(); + } catch (InterruptedException e) { + logger.error("Interrupted whilst moving players", e); + Thread.currentThread().interrupt(); } - } - try { - latch.await(); - } catch (InterruptedException e) { - logger.error("Interrupted whilst moving players", e); - Thread.currentThread().interrupt(); } // If we have a new bind address, bind to it