diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index ed0593de2..2a0927ecf 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -105,6 +105,14 @@ public interface ProxyServer extends Audience { */ Collection matchServer(String partialName); + /** + * Creates a raw {@link RegisteredServer} without tying it into the internal server map. + * + * @param server the server to register + * @return the {@link RegisteredServer} implementation created by the provided {@link ServerInfo}. + */ + RegisteredServer createRawRegisteredServer(ServerInfo server); + /** * Registers a server with this proxy. A server with this name should not already exist. * diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index ed3bbf801..a060183e8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -600,6 +600,11 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { return servers.getAllServers(); } + @Override + public RegisteredServer createRawRegisteredServer(ServerInfo server) { + return servers.createRawRegisteredServer(server); + } + @Override public RegisteredServer registerServer(ServerInfo server) { return servers.register(server); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java index 41d337be0..00fc2edd6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java @@ -54,6 +54,17 @@ public class ServerMap { return ImmutableList.copyOf(servers.values()); } + /** + * Creates a raw implementation of a {@link RegisteredServer} without + * tying it to the internal server map. + * + * @param serverInfo the server to create a registered server with + * @return the {@link RegisteredServer} built from the {@link ServerInfo} + */ + public RegisteredServer createRawRegisteredServer(ServerInfo serverInfo) { + return new VelocityRegisteredServer(server, serverInfo); + } + /** * Registers a server with the proxy. * @@ -63,7 +74,7 @@ public class ServerMap { public RegisteredServer register(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); String lowerName = serverInfo.getName().toLowerCase(Locale.US); - VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo); + RegisteredServer rs = createRawRegisteredServer(serverInfo); RegisteredServer existing = servers.putIfAbsent(lowerName, rs); if (existing != null && !existing.getServerInfo().equals(serverInfo)) {