Remove ServerBuilder
This commit is contained in:
@@ -45,4 +45,6 @@ public interface PlatformMethods {
|
||||
boolean hasPlugin(String pluginName);
|
||||
|
||||
AdaptedServer getServer(String name);
|
||||
|
||||
List<AdaptedServer> getServers();
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package us.ajg0702.queue.api.server;
|
||||
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ServerBuilder {
|
||||
List<AdaptedServer> getServers();
|
||||
|
||||
AdaptedServer getServer(String name);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class Send extends SubCommand {
|
||||
);
|
||||
} else if(main.getQueueManager().getServerNames().contains(args[0])) {
|
||||
|
||||
AdaptedServer from = main.getServerBuilder().getServer(args[0]);
|
||||
AdaptedServer from = main.getPlatformMethods().getServer(args[0]);
|
||||
if(from == null) {
|
||||
sender.sendMessage(getMessages().getComponent("errors.server-not-exist", "SERVER:"+args[0]));
|
||||
return;
|
||||
|
||||
@@ -2,7 +2,6 @@ package us.ajg0702.queue.common;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import us.ajg0702.queue.api.*;
|
||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||
import us.ajg0702.queue.api.util.QueueLogger;
|
||||
import us.ajg0702.queue.common.utils.LogConverter;
|
||||
import us.ajg0702.queue.logic.LogicGetterImpl;
|
||||
@@ -10,10 +9,7 @@ import us.ajg0702.utils.common.Config;
|
||||
import us.ajg0702.utils.common.Messages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class QueueMain {
|
||||
|
||||
@@ -74,27 +70,6 @@ public class QueueMain {
|
||||
return eventHandler;
|
||||
}
|
||||
|
||||
private final List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
|
||||
private ServerBuilder serverBuilder;
|
||||
public ServerBuilder getServerBuilder() {
|
||||
return serverBuilder;
|
||||
}
|
||||
public CompletableFuture<ServerBuilder> getFutureServerBuilder() {
|
||||
CompletableFuture<ServerBuilder> completableFuture = new CompletableFuture<>();
|
||||
if(serverBuilder != null) {
|
||||
completableFuture.complete(serverBuilder);
|
||||
}
|
||||
serverCompletableFutures.add(completableFuture);
|
||||
return completableFuture;
|
||||
}
|
||||
public void setServerBuilder(ServerBuilder serverBuilder) {
|
||||
if(this.serverBuilder != null) throw new IllegalStateException("SeverBuilder already set");
|
||||
this.serverBuilder = serverBuilder;
|
||||
for(CompletableFuture<ServerBuilder> future : serverCompletableFutures) {
|
||||
future.complete(serverBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
private QueueManager queueManager;
|
||||
public QueueManager getQueueManager() {
|
||||
return queueManager;
|
||||
|
||||
@@ -6,14 +6,15 @@ import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||
import us.ajg0702.queue.common.queues.QueueServerImpl;
|
||||
import us.ajg0702.utils.common.Messages;
|
||||
import us.ajg0702.utils.common.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -30,15 +31,12 @@ public class QueueManagerImpl implements QueueManager {
|
||||
|
||||
int delay = main.getConfig().getBoolean("wait-to-load-servers") ? main.getConfig().getInt("wait-to-load-servers-delay") : 0;
|
||||
|
||||
main.getTaskManager().runLater(() -> {
|
||||
CompletableFuture<ServerBuilder> serverBuilderFuture = main.getFutureServerBuilder();
|
||||
serverBuilderFuture.thenRunAsync(this::reloadServers);
|
||||
}, delay, TimeUnit.MILLISECONDS);
|
||||
main.getTaskManager().runLater(this::reloadServers, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public List<QueueServer> buildServers() {
|
||||
List<QueueServer> result = new ArrayList<>();
|
||||
List<AdaptedServer> servers = main.getServerBuilder().getServers();
|
||||
List<AdaptedServer> servers = main.getPlatformMethods().getServers();
|
||||
|
||||
for(AdaptedServer server : servers) {
|
||||
QueueServer previousServer = main.getQueueManager().findServer(server.getName());
|
||||
|
||||
+9
@@ -110,4 +110,13 @@ public class BungeeMethods implements PlatformMethods {
|
||||
if(server == null) return null;
|
||||
return new BungeeServer(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdaptedServer> getServers() {
|
||||
List<AdaptedServer> result = new ArrayList<>();
|
||||
|
||||
proxyServer.getServers().forEach((s, serverInfo) -> result.add(new BungeeServer(serverInfo)));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -20,7 +20,6 @@ import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.platforms.bungeecord.commands.BungeeCommand;
|
||||
import us.ajg0702.queue.platforms.bungeecord.players.BungeePlayer;
|
||||
import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer;
|
||||
import us.ajg0702.queue.platforms.bungeecord.server.BungeeServerBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -42,7 +41,6 @@ public class BungeeQueue extends Plugin implements Listener {
|
||||
new BungeeMethods(this, getProxy(), logger),
|
||||
dataFolder
|
||||
);
|
||||
main.setServerBuilder(new BungeeServerBuilder(getProxy()));
|
||||
|
||||
getProxy().registerChannel("ajqueue:tospigot");
|
||||
getProxy().registerChannel("ajqueue:toproxy");
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package us.ajg0702.queue.platforms.bungeecord.server;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeServerBuilder implements ServerBuilder {
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
|
||||
public BungeeServerBuilder(ProxyServer proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdaptedServer> getServers() {
|
||||
List<AdaptedServer> result = new ArrayList<>();
|
||||
|
||||
proxyServer.getServers().forEach((s, serverInfo) -> result.add(new BungeeServer(serverInfo)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdaptedServer getServer(String name) {
|
||||
ServerInfo server = proxyServer.getServerInfo(name);
|
||||
if(server == null) return null;
|
||||
return new BungeeServer(server);
|
||||
}
|
||||
}
|
||||
+10
@@ -132,4 +132,14 @@ public class VelocityMethods implements PlatformMethods {
|
||||
if(!server.isPresent()) return null;
|
||||
return new VelocityServer(server.get());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<AdaptedServer> getServers() {
|
||||
List<AdaptedServer> result = new ArrayList<>();
|
||||
|
||||
proxyServer.getAllServers().forEach(registeredServer -> result.add(new VelocityServer(registeredServer)));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -15,6 +15,7 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.slf4j.Logger;
|
||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||
import us.ajg0702.queue.commands.BaseCommand;
|
||||
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||
@@ -24,7 +25,7 @@ import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
||||
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
||||
import us.ajg0702.queue.platforms.velocity.server.VelocityServerBuilder;
|
||||
import us.ajg0702.queue.platforms.velocity.server.VelocityServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
@@ -32,9 +33,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import us.ajg0702.queue.platforms.velocity.server.VelocityServer;
|
||||
|
||||
@Plugin(
|
||||
id = "ajqueue",
|
||||
name = "ajQueue",
|
||||
@@ -69,7 +67,6 @@ public class VelocityQueue {
|
||||
new VelocityMethods(this, proxyServer, logger),
|
||||
dataFolder
|
||||
);
|
||||
main.setServerBuilder(new VelocityServerBuilder(proxyServer));
|
||||
|
||||
commands = Arrays.asList(
|
||||
new QueueCommand(main),
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package us.ajg0702.queue.platforms.velocity.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class VelocityServerBuilder implements ServerBuilder {
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
|
||||
public VelocityServerBuilder(ProxyServer proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdaptedServer> getServers() {
|
||||
List<AdaptedServer> result = new ArrayList<>();
|
||||
|
||||
proxyServer.getAllServers().forEach(registeredServer -> result.add(new VelocityServer(registeredServer)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalIsPresent")
|
||||
@Override
|
||||
public AdaptedServer getServer(String name) {
|
||||
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
|
||||
if(!serverOptional.isPresent()) return null;
|
||||
return new VelocityServer(serverOptional.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user