From f5693532137a05dd4854c3d2478a4b708356726a Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sat, 31 Jul 2021 14:11:30 -0700 Subject: [PATCH] check if a player is in a queue server and isnt queued --- .../us/ajg0702/queue/api/PlatformMethods.java | 3 +++ .../queue/common/QueueManagerImpl.java | 19 +++++++++++++++++-- .../platforms/bungeecord/BungeeMethods.java | 10 ++++++++++ .../platforms/velocity/VelocityMethods.java | 10 ++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java b/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java index 8cd0433..91c2256 100644 --- a/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java +++ b/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java @@ -3,6 +3,7 @@ package us.ajg0702.queue.api; import us.ajg0702.queue.api.commands.IBaseCommand; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.api.server.AdaptedServer; import java.util.List; @@ -42,4 +43,6 @@ public interface PlatformMethods { * @return if the plugin is on the server */ boolean hasPlugin(String pluginName); + + AdaptedServer getServer(String name); } diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java index 545274f..7dcec34 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -194,8 +194,8 @@ public class QueueManagerImpl implements QueueManager { servers.addAll(main.getServerBuilder().buildServers()); - List groupsraw = main.getConfig().getStringList("server-groups"); - for(String groupraw : groupsraw) { + List groupsRaw = main.getConfig().getStringList("server-groups"); + for(String groupraw : groupsRaw) { if(groupraw.isEmpty()) { main.getLogger().warning("Empty group string! If you dont want server groups, set server-groups like this: server-groups: []"); continue; @@ -272,6 +272,21 @@ public class QueueManagerImpl implements QueueManager { @Override public void sendQueueEvents() { + List svs = main.getConfig().getStringList("queue-servers"); + for(String s : svs) { + if(!s.contains(":")) continue; + String[] parts = s.split(":"); + String fromName = parts[0]; + String toName = parts[1]; + AdaptedServer from = main.getPlatformMethods().getServer(fromName); + QueueServer to = findServer(toName); + if(from == null || to == null) continue; + from.getPlayers().forEach(player -> { + if(!getPlayerQueues(player).contains(to)) { + addToQueue(player, to); + } + }); + } for (QueueServer s : servers) { for (QueuePlayer queuePlayer : s.getQueue()) { AdaptedPlayer player = queuePlayer.getPlayer(); diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeMethods.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeMethods.java index 7c55d47..d334c34 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeMethods.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeMethods.java @@ -3,14 +3,17 @@ package us.ajg0702.queue.platforms.bungeecord; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import us.ajg0702.queue.api.PlatformMethods; import us.ajg0702.queue.api.commands.IBaseCommand; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.api.server.AdaptedServer; import us.ajg0702.queue.api.util.QueueLogger; import us.ajg0702.queue.commands.commands.PlayerSender; import us.ajg0702.queue.platforms.bungeecord.players.BungeePlayer; +import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer; import java.util.ArrayList; import java.util.Collection; @@ -100,4 +103,11 @@ public class BungeeMethods implements PlatformMethods { public boolean hasPlugin(String pluginName) { return proxyServer.getPluginManager().getPlugin(pluginName) != null; } + + @Override + public AdaptedServer getServer(String name) { + ServerInfo server = proxyServer.getServerInfo(name); + if(server == null) return null; + return new BungeeServer(server); + } } diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityMethods.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityMethods.java index 4517550..993ec9e 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityMethods.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityMethods.java @@ -13,15 +13,18 @@ import us.ajg0702.queue.api.PlatformMethods; import us.ajg0702.queue.api.commands.IBaseCommand; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.api.server.AdaptedServer; import us.ajg0702.queue.api.util.QueueLogger; import us.ajg0702.queue.commands.commands.PlayerSender; import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer; +import us.ajg0702.queue.platforms.velocity.server.VelocityServer; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Optional; +@SuppressWarnings("OptionalIsPresent") public class VelocityMethods implements PlatformMethods { final ProxyServer proxyServer; @@ -122,4 +125,11 @@ public class VelocityMethods implements PlatformMethods { public boolean hasPlugin(String pluginName) { return proxyServer.getPluginManager().getPlugin(pluginName.toLowerCase(Locale.ROOT)).isPresent(); } + + @Override + public AdaptedServer getServer(String name) { + Optional server = proxyServer.getServer(name); + if(!server.isPresent()) return null; + return new VelocityServer(server.get()); + } }