Introduce RegisteredServer API
This interface roughly maps the BungeeCord ServerInfo API. Accordingly, this is a breaking API change, as many of the server-related events and methods working with server info instances now provide/expect the RegisteredServer interface instead.
This commit is contained in:
@@ -3,6 +3,7 @@ package com.velocitypowered.api.event.player;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import net.kyori.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -13,12 +14,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
*/
|
||||
public class KickedFromServerEvent implements ResultedEvent<KickedFromServerEvent.ServerKickResult> {
|
||||
private final Player player;
|
||||
private final ServerInfo server;
|
||||
private final RegisteredServer server;
|
||||
private final Component originalReason;
|
||||
private final boolean duringLogin;
|
||||
private ServerKickResult result;
|
||||
|
||||
public KickedFromServerEvent(Player player, ServerInfo server, Component originalReason, boolean duringLogin, Component fancyReason) {
|
||||
public KickedFromServerEvent(Player player, RegisteredServer server, Component originalReason, boolean duringLogin, Component fancyReason) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.server = Preconditions.checkNotNull(server, "server");
|
||||
this.originalReason = Preconditions.checkNotNull(originalReason, "originalReason");
|
||||
@@ -40,7 +41,7 @@ public class KickedFromServerEvent implements ResultedEvent<KickedFromServerEven
|
||||
return player;
|
||||
}
|
||||
|
||||
public ServerInfo getServer() {
|
||||
public RegisteredServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -91,9 +92,9 @@ public class KickedFromServerEvent implements ResultedEvent<KickedFromServerEven
|
||||
* when this result is used.
|
||||
*/
|
||||
public static class RedirectPlayer implements ServerKickResult {
|
||||
private final ServerInfo server;
|
||||
private final RegisteredServer server;
|
||||
|
||||
private RedirectPlayer(ServerInfo server) {
|
||||
private RedirectPlayer(RegisteredServer server) {
|
||||
this.server = Preconditions.checkNotNull(server, "server");
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ public class KickedFromServerEvent implements ResultedEvent<KickedFromServerEven
|
||||
return false;
|
||||
}
|
||||
|
||||
public ServerInfo getServer() {
|
||||
public RegisteredServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -111,7 +112,7 @@ public class KickedFromServerEvent implements ResultedEvent<KickedFromServerEven
|
||||
* @param server the server to send the player to
|
||||
* @return the redirect result
|
||||
*/
|
||||
public static RedirectPlayer create(ServerInfo server) {
|
||||
public static RedirectPlayer create(RegisteredServer server) {
|
||||
return new RedirectPlayer(server);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package com.velocitypowered.api.event.player;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
|
||||
/**
|
||||
* This event is fired once the player has successfully connected to the target server and the connection to the previous
|
||||
@@ -10,9 +10,9 @@ import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
*/
|
||||
public class ServerConnectedEvent {
|
||||
private final Player player;
|
||||
private final ServerInfo server;
|
||||
private final RegisteredServer server;
|
||||
|
||||
public ServerConnectedEvent(Player player, ServerInfo server) {
|
||||
public ServerConnectedEvent(Player player, RegisteredServer server) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.server = Preconditions.checkNotNull(server, "server");
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class ServerConnectedEvent {
|
||||
return player;
|
||||
}
|
||||
|
||||
public ServerInfo getServer() {
|
||||
public RegisteredServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package com.velocitypowered.api.event.player;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -14,10 +15,10 @@ import java.util.Optional;
|
||||
*/
|
||||
public class ServerPreConnectEvent implements ResultedEvent<ServerPreConnectEvent.ServerResult> {
|
||||
private final Player player;
|
||||
private final ServerInfo originalServer;
|
||||
private final RegisteredServer originalServer;
|
||||
private ServerResult result;
|
||||
|
||||
public ServerPreConnectEvent(Player player, ServerInfo originalServer) {
|
||||
public ServerPreConnectEvent(Player player, RegisteredServer originalServer) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer");
|
||||
this.result = ServerResult.allowed(originalServer);
|
||||
@@ -37,7 +38,7 @@ public class ServerPreConnectEvent implements ResultedEvent<ServerPreConnectEven
|
||||
this.result = Preconditions.checkNotNull(result, "result");
|
||||
}
|
||||
|
||||
public ServerInfo getOriginalServer() {
|
||||
public RegisteredServer getOriginalServer() {
|
||||
return originalServer;
|
||||
}
|
||||
|
||||
@@ -57,9 +58,9 @@ public class ServerPreConnectEvent implements ResultedEvent<ServerPreConnectEven
|
||||
private static final ServerResult DENIED = new ServerResult(false, null);
|
||||
|
||||
private final boolean allowed;
|
||||
private final ServerInfo server;
|
||||
private final RegisteredServer server;
|
||||
|
||||
private ServerResult(boolean allowed, @Nullable ServerInfo server) {
|
||||
private ServerResult(boolean allowed, @Nullable RegisteredServer server) {
|
||||
this.allowed = allowed;
|
||||
this.server = server;
|
||||
}
|
||||
@@ -69,7 +70,7 @@ public class ServerPreConnectEvent implements ResultedEvent<ServerPreConnectEven
|
||||
return allowed;
|
||||
}
|
||||
|
||||
public Optional<ServerInfo> getServer() {
|
||||
public Optional<RegisteredServer> getServer() {
|
||||
return Optional.ofNullable(server);
|
||||
}
|
||||
|
||||
@@ -78,14 +79,14 @@ public class ServerPreConnectEvent implements ResultedEvent<ServerPreConnectEven
|
||||
if (!allowed) {
|
||||
return "denied";
|
||||
}
|
||||
return "allowed: connect to " + server.getName();
|
||||
return "allowed: connect to " + server.getServerInfo().getName();
|
||||
}
|
||||
|
||||
public static ServerResult denied() {
|
||||
return DENIED;
|
||||
}
|
||||
|
||||
public static ServerResult allowed(ServerInfo server) {
|
||||
public static ServerResult allowed(RegisteredServer server) {
|
||||
Preconditions.checkNotNull(server, "server");
|
||||
return new ServerResult(true, server);
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.velocitypowered.api.proxy;
|
||||
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import net.kyori.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -9,21 +10,21 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Provides a fluent interface to compose and send a connection request to another server behind the proxy. A connection
|
||||
* request is created using {@link Player#createConnectionRequest(ServerInfo)}.
|
||||
* request is created using {@link Player#createConnectionRequest(RegisteredServer)}.
|
||||
*/
|
||||
public interface ConnectionRequestBuilder {
|
||||
/**
|
||||
* Returns the server that this connection request represents.
|
||||
* @return the server this request will connect to
|
||||
*/
|
||||
@NonNull ServerInfo getServer();
|
||||
RegisteredServer 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
|
||||
*/
|
||||
@NonNull CompletableFuture<Result> connect();
|
||||
CompletableFuture<Result> connect();
|
||||
|
||||
/**
|
||||
* Initiates the connection to the remote server without waiting for a result. Velocity will use generic error
|
||||
|
@@ -4,6 +4,7 @@ import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.util.MessagePosition;
|
||||
import net.kyori.text.Component;
|
||||
@@ -59,10 +60,10 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
||||
|
||||
/**
|
||||
* Creates a new connection request so that the player can connect to another server.
|
||||
* @param info the server to connect to
|
||||
* @param server the server to connect to
|
||||
* @return a new connection request
|
||||
*/
|
||||
ConnectionRequestBuilder createConnectionRequest(@NonNull ServerInfo info);
|
||||
ConnectionRequestBuilder createConnectionRequest(@NonNull RegisteredServer server);
|
||||
|
||||
/**
|
||||
* Sets the tab list header and footer for the player.
|
||||
|
@@ -5,6 +5,7 @@ import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.event.EventManager;
|
||||
import com.velocitypowered.api.plugin.PluginManager;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.scheduler.Scheduler;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
|
||||
@@ -45,23 +46,24 @@ public interface ProxyServer {
|
||||
int getPlayerCount();
|
||||
|
||||
/**
|
||||
* Retrieves a registered {@link ServerInfo} instance by its name. The search is case-insensitive.
|
||||
* Retrieves a registered {@link RegisteredServer} instance by its name. The search is case-insensitive.
|
||||
* @param name the name of the server
|
||||
* @return the registered server, which may be empty
|
||||
*/
|
||||
Optional<ServerInfo> getServerInfo(String name);
|
||||
Optional<RegisteredServer> getServerInfo(String name);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link ServerInfo}s registered with this proxy.
|
||||
* Retrieves all {@link RegisteredServer}s registered with this proxy.
|
||||
* @return the servers registered with this proxy
|
||||
*/
|
||||
Collection<ServerInfo> getAllServers();
|
||||
Collection<RegisteredServer> getAllServers();
|
||||
|
||||
/**
|
||||
* Registers a server with this proxy. A server with this name should not already exist.
|
||||
* @param server the server to register
|
||||
* @return the newly registered server
|
||||
*/
|
||||
void registerServer(ServerInfo server);
|
||||
RegisteredServer registerServer(ServerInfo server);
|
||||
|
||||
/**
|
||||
* Unregisters this server from the proxy.
|
||||
|
@@ -2,6 +2,7 @@ package com.velocitypowered.api.proxy;
|
||||
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,12 @@ public interface ServerConnection extends ChannelMessageSource, ChannelMessageSi
|
||||
* Returns the server that this connection is connected to.
|
||||
* @return the server this connection is connected to
|
||||
*/
|
||||
RegisteredServer getServer();
|
||||
|
||||
/**
|
||||
* Returns the server info for this connection.
|
||||
* @return the server info for this connection
|
||||
*/
|
||||
ServerInfo getServerInfo();
|
||||
|
||||
/**
|
||||
|
@@ -8,6 +8,7 @@ public interface ChannelMessageSink {
|
||||
* Sends a plugin message to this target.
|
||||
* @param identifier the channel identifier to send the message on
|
||||
* @param data the data to send
|
||||
* @return whether or not the message could be sent
|
||||
*/
|
||||
void sendPluginMessage(ChannelIdentifier identifier, byte[] data);
|
||||
boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data);
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package com.velocitypowered.api.proxy.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Represents a server that has been registered with the proxy.
|
||||
*/
|
||||
public interface RegisteredServer extends ChannelMessageSink {
|
||||
/**
|
||||
* Returns the {@link ServerInfo} for this server.
|
||||
* @return the server info
|
||||
*/
|
||||
ServerInfo getServerInfo();
|
||||
|
||||
/**
|
||||
* Returns a list of all the players currently connected to this server on this proxy.
|
||||
* @return the players on this proxy
|
||||
*/
|
||||
Collection<Player> getPlayersConnected();
|
||||
|
||||
/**
|
||||
* Attempts to ping the remote server and return the server list ping result.
|
||||
* @return the server ping result from the server
|
||||
*/
|
||||
CompletableFuture<ServerPing> ping();
|
||||
}
|
Reference in New Issue
Block a user