From 3bd48dec998088c03a4683fb44e4a8f79f2dbd61 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 21 Oct 2018 17:49:51 -0400 Subject: [PATCH] Add convenience connectWithIndication() method. --- .../api/proxy/ConnectionRequestBuilder.java | 7 +++++++ .../proxy/connection/client/ConnectedPlayer.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java b/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java index d7369a15c..e9108c645 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java @@ -24,6 +24,13 @@ public interface ConnectionRequestBuilder { */ CompletableFuture connect(); + /** + * Initiates the connection to the remote server and emits a result on the {@link CompletableFuture} after the user + * has logged on. Velocity's own built-in handling will be used to provide errors to the client. + * @return a {@link CompletableFuture} representing the status of this connection + */ + CompletableFuture connectWithIndication(); + /** * Initiates the connection to the remote server without waiting for a result. Velocity will use generic error * handling code to notify the user. 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 c187d5d9b..a9bd165bc 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 @@ -467,8 +467,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public void fireAndForget() { - connect() + public CompletableFuture connectWithIndication() { + return connect() .whenCompleteAsync((status, throwable) -> { if (throwable != null) { handleConnectionException(server, throwable); @@ -489,7 +489,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { handleConnectionException(server, Disconnect.create(status.getReason().orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR))); break; } - }, connection.eventLoop()); + }, connection.eventLoop()) + .thenApply(Result::isSuccessful); + } + + @Override + public void fireAndForget() { + connectWithIndication(); } } }