13
0
geforkt von Mirrors/Velocity

Make connections more robust

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-19 21:29:07 -04:00
Ursprung 08d596b76d
Commit 95c761479f

Datei anzeigen

@ -262,17 +262,21 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return server.getServers().getServer(toTryName); return server.getServers().getServer(toTryName);
} }
private CompletableFuture<ConnectionRequestBuilder.Result> connect(ConnectionRequestBuilderImpl request) { private Optional<ConnectionRequestBuilder.Status> checkServer(RegisteredServer server) {
Preconditions.checkState(server instanceof VelocityRegisteredServer, "Not a valid Velocity server.");
if (connectionInFlight != null) { if (connectionInFlight != null) {
return CompletableFuture.completedFuture( return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS);
ConnectionRequestResults.plainResult(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS) }
); if (connectedServer != null && connectedServer.getServer().equals(server)) {
return Optional.of(ConnectionRequestBuilder.Status.ALREADY_CONNECTED);
}
return Optional.empty();
} }
if (connectedServer != null && connectedServer.getServerInfo().equals(request.getServer())) { private CompletableFuture<ConnectionRequestBuilder.Result> connect(ConnectionRequestBuilderImpl request) {
return CompletableFuture.completedFuture( Optional<ConnectionRequestBuilder.Status> initialCheck = checkServer(request.getServer());
ConnectionRequestResults.plainResult(ConnectionRequestBuilder.Status.ALREADY_CONNECTED) if (initialCheck.isPresent()) {
); return CompletableFuture.completedFuture(ConnectionRequestResults.plainResult(initialCheck.get()));
} }
// Otherwise, initiate the connection. // Otherwise, initiate the connection.
@ -286,7 +290,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
RegisteredServer rs = newEvent.getResult().getServer().get(); RegisteredServer rs = newEvent.getResult().getServer().get();
Preconditions.checkState(rs instanceof VelocityRegisteredServer, "Not a valid Velocity server."); Optional<ConnectionRequestBuilder.Status> lastCheck = checkServer(rs);
if (lastCheck.isPresent()) {
return CompletableFuture.completedFuture(ConnectionRequestResults.plainResult(lastCheck.get()));
}
return new VelocityServerConnection((VelocityRegisteredServer) rs, this, server).connect(); return new VelocityServerConnection((VelocityRegisteredServer) rs, this, server).connect();
}); });
} }