Introduce a fluent connection request API.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.velocitypowered.api.proxy;
|
||||
|
||||
import com.velocitypowered.api.server.ServerInfo;
|
||||
import net.kyori.text.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Represents a connection request. A connection request is created using {@link Player#createConnectionRequest(ServerInfo)}
|
||||
* and is used to allow a plugin to compose and request a connection to another Minecraft server using a fluent API.
|
||||
*/
|
||||
public interface ConnectionRequestBuilder {
|
||||
/**
|
||||
* Returns the server that this connection request represents.
|
||||
* @return the server this request will connect to
|
||||
*/
|
||||
ServerInfo getServer();
|
||||
|
||||
/**
|
||||
* Initiates the connection to the remote server and emits a result on the {@link CompletableFuture} after the user
|
||||
* has logged on. No messages will be communicated to the client: the user is responsible for all error handling.
|
||||
* @return a {@link CompletableFuture} representing the status of this connection
|
||||
*/
|
||||
CompletableFuture<Result> connect();
|
||||
|
||||
/**
|
||||
* Initiates the connection to the remote server without waiting for a result. Velocity will use generic error
|
||||
* handling code to notify the user.
|
||||
*/
|
||||
void fireAndForget();
|
||||
|
||||
/**
|
||||
* Represents the result of a connection request.
|
||||
*/
|
||||
interface Result {
|
||||
/**
|
||||
* Determines whether or not the connection request was successful.
|
||||
* @return whether or not the request succeeded
|
||||
*/
|
||||
default boolean isSuccessful() {
|
||||
return getStatus() == Status.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status associated with this result.
|
||||
* @return the status for this result
|
||||
*/
|
||||
Status getStatus();
|
||||
|
||||
/**
|
||||
* Returns a reason for the failure to connect to the server. None may be provided.
|
||||
* @return the reason why the user could not connect to the server
|
||||
*/
|
||||
Optional<Component> getReason();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the status of a connection request initiated by a {@link ConnectionRequestBuilder}.
|
||||
*/
|
||||
enum Status {
|
||||
/**
|
||||
* The player was successfully connected to the server.
|
||||
*/
|
||||
SUCCESS,
|
||||
/**
|
||||
* The player is already connected to this server.
|
||||
*/
|
||||
ALREADY_CONNECTED,
|
||||
/**
|
||||
* The connection is already in progress.
|
||||
*/
|
||||
CONNECTION_IN_PROGRESS,
|
||||
/**
|
||||
* A plugin has cancelled this connection.
|
||||
*/
|
||||
CONNECTION_CANCELLED,
|
||||
/**
|
||||
* The server disconnected the user. A reason may be provided in the {@link Result} object.
|
||||
*/
|
||||
SERVER_DISCONNECTED
|
||||
}
|
||||
|
||||
}
|
@@ -57,4 +57,11 @@ public interface Player {
|
||||
* @param position the position for the message
|
||||
*/
|
||||
void sendMessage(@Nonnull Component component, @Nonnull MessagePosition position);
|
||||
|
||||
/**
|
||||
* Creates a new connection request so that the player can connect to another server.
|
||||
* @param info the server to connect to
|
||||
* @return a new connection request
|
||||
*/
|
||||
ConnectionRequestBuilder createConnectionRequest(@Nonnull ServerInfo info);
|
||||
}
|
||||
|
Reference in New Issue
Block a user