From 6f24594945c3152be87e67cf88ef25e8cafe3907 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 12 Jul 2021 14:14:34 -0700 Subject: [PATCH] the basics are working on velocity now --- .../us/ajg0702/queue/api/QueueManager.java | 5 + .../commands/listqueues/ListCommand.java | 91 +++++++++++++ .../commands/manage/ManageCommand.java | 30 ++++- .../commands/commands/manage/Reload.java | 70 ++++++++++ .../queue/commands/commands/manage/Tasks.java | 58 +++++++++ .../commands/commands/queue/QueueCommand.java | 7 +- .../us/ajg0702/queue/common/QueueMain.java | 14 +- .../queue/common/QueueManagerImpl.java | 44 +++++-- .../us/ajg0702/queue/common/TaskManager.java | 123 ++++++++++++++++++ .../queue/common/players/QueuePlayerImpl.java | 1 + .../queue/common/queues/QueueServerImpl.java | 17 ++- common/src/main/resources/config.yml | 9 +- .../platforms/velocity/VelocityQueue.java | 6 +- .../velocity/players/VelocityPlayer.java | 3 +- .../velocity/server/VelocityServerPing.java | 4 +- 15 files changed, 457 insertions(+), 25 deletions(-) create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/listqueues/ListCommand.java create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/manage/Reload.java create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java create mode 100644 common/src/main/java/us/ajg0702/queue/common/TaskManager.java diff --git a/api/src/main/java/us/ajg0702/queue/api/QueueManager.java b/api/src/main/java/us/ajg0702/queue/api/QueueManager.java index a86267a..0fc512b 100644 --- a/api/src/main/java/us/ajg0702/queue/api/QueueManager.java +++ b/api/src/main/java/us/ajg0702/queue/api/QueueManager.java @@ -79,6 +79,11 @@ public interface QueueManager { */ void sendMessage(QueuePlayer queuePlayer); + /** + * Updates info about the servers + */ + void updateServers(); + /** * Find a server by its name * @param name The name to look for diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/listqueues/ListCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/listqueues/ListCommand.java new file mode 100644 index 0000000..64d4958 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/listqueues/ListCommand.java @@ -0,0 +1,91 @@ +package us.ajg0702.queue.commands.commands.listqueues; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.commands.ISubCommand; +import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.api.queues.QueueServer; +import us.ajg0702.queue.commands.BaseCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ListCommand extends BaseCommand { + + private final QueueMain main; + + public ListCommand(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "listqueues"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of("listq"); + } + + @Override + public ImmutableList getSubCommands() { + return ImmutableList.builder().build(); + } + + @Override + public String getPermission() { + return "ajqueue.listqueues"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void addSubCommand(ISubCommand subCommand) { + + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + + AdaptedPlayer spp = null; + if(sender.isPlayer()) { + spp = main.getPlatformMethods().senderToPlayer(sender); + } + + + Component m = main.getMessages().getComponent("commands.listqueues.header"); + boolean none = true; + for(QueueServer s : main.getQueueManager().getServers()) { + none = false; + String color = "&a"; + if(!s.isOnline()) { + color = "&c"; + } else if(!s.isJoinable(spp)) { + color = "&e"; + } + + m = m.append(Component.text("\n")); + m = m.append(main.getMessages().getComponent("commands.listqueues.format", + "COLOR:" + main.getMessages().color(color), + "NAME:" + s.getName(), + "COUNT:" + s.getQueue().size(), + "STATUS:" + s.getStatusString(spp) + )); + } + sender.sendMessage(m); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java index 49413c9..4987e3f 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java @@ -1,6 +1,7 @@ package us.ajg0702.queue.commands.commands.manage; import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.api.commands.ISubCommand; import us.ajg0702.queue.commands.BaseCommand; @@ -9,7 +10,9 @@ import us.ajg0702.queue.common.QueueMain; import us.ajg0702.utils.common.Messages; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class ManageCommand extends BaseCommand { @@ -18,7 +21,8 @@ public class ManageCommand extends BaseCommand { public ManageCommand(QueueMain main) { this.main = main; - + addSubCommand(new Reload(main)); + addSubCommand(new Tasks(main)); } @@ -56,11 +60,31 @@ public class ManageCommand extends BaseCommand { @Override public void execute(ICommandSender sender, String[] args) { - + if(args.length > 0) { + for(ISubCommand subCommand : subCommands) { + if(args[0].equalsIgnoreCase(subCommand.getName()) || subCommand.getAliases().contains(args[0].toLowerCase(Locale.ROOT))) { + subCommand.execute(sender, Arrays.copyOfRange(args, 1, args.length)); + return; + } + } + } + sender.sendMessage(Component.text("/ajQueue ")); } @Override public List autoComplete(ICommandSender sender, String[] args) { - return null; + if(args.length > 0) { + for(ISubCommand subCommand : subCommands) { + if(args[0].equalsIgnoreCase(subCommand.getName()) || subCommand.getAliases().contains(args[0].toLowerCase(Locale.ROOT))) { + return subCommand.autoComplete(sender, Arrays.copyOfRange(args, 1, args.length)); + } + } + } + List commands = new ArrayList<>(); + for(ISubCommand subCommand : subCommands) { + commands.add(subCommand.getName()); + commands.addAll(subCommand.getAliases()); + } + return commands; } } diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Reload.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Reload.java new file mode 100644 index 0000000..2007771 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Reload.java @@ -0,0 +1,70 @@ +package us.ajg0702.queue.commands.commands.manage; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.spongepowered.configurate.ConfigurateException; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.commands.ISubCommand; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.List; + +public class Reload extends SubCommand { + + QueueMain main; + public Reload(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "reload"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.reload"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void addSubCommand(ISubCommand subCommand) { + + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + main.getMessages().reload(); + try { + main.getConfig().reload(); + } catch (ConfigurateException e) { + sender.sendMessage(Component.text("An error occurred while reloading. Check the console").color(NamedTextColor.RED)); + e.printStackTrace(); + return; + } + main.setTimeBetweenPlayers(); + main.getTaskManager().rescheduleTasks(); + main.getQueueManager().reloadServers(); + + sender.sendMessage(getMessages().getComponent("commands.reload")); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java new file mode 100644 index 0000000..996484e --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java @@ -0,0 +1,58 @@ +package us.ajg0702.queue.commands.commands.manage; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.spongepowered.configurate.ConfigurateException; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.commands.ISubCommand; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.List; + +public class Tasks extends SubCommand { + + QueueMain main; + public Tasks(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "tasks"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.tasks"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void addSubCommand(ISubCommand subCommand) { + + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + sender.sendMessage(Component.text(main.getTaskManager().taskStatus())); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java index 7de09a9..149fef6 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/queue/QueueCommand.java @@ -9,6 +9,7 @@ import us.ajg0702.queue.common.QueueMain; import us.ajg0702.utils.common.Messages; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class QueueCommand extends BaseCommand { @@ -26,7 +27,11 @@ public class QueueCommand extends BaseCommand { @Override public ImmutableList getAliases() { - return ImmutableList.of("move", "server", "joinqueue", "joinq"); + List aliases = new ArrayList<>(Arrays.asList("move", "joinqueue", "joinq")); + if(main.getConfig().getBoolean("enable-server-command")) { + aliases.add("server"); + } + return ImmutableList.copyOf(aliases); } @Override diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java index fa4593c..ba72f8a 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java @@ -14,7 +14,7 @@ import java.io.File; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; -import java.util.concurrent.CompletableFuture; +import java.util.concurrent.*; import java.util.logging.Logger; public class QueueMain { @@ -24,6 +24,9 @@ public class QueueMain { public double getTimeBetweenPlayers() { return timeBetweenPlayers; } + public void setTimeBetweenPlayers() { + this.timeBetweenPlayers = config.getDouble("wait-time"); + } private Config config; public Config getConfig() { @@ -59,6 +62,11 @@ public class QueueMain { return logger; } + private final TaskManager taskManager = new TaskManager(this); + public TaskManager getTaskManager() { + return taskManager; + } + private List> serverCompletableFutures = new ArrayList<>(); private ServerBuilder serverBuilder; public ServerBuilder getServerBuilder() { @@ -104,14 +112,14 @@ public class QueueMain { return; } - timeBetweenPlayers = config.getDouble("wait-time"); + setTimeBetweenPlayers(); queueManager = new QueueManagerImpl(this); logic = new LogicGetter().constructLogic(); aliasManager = new LogicGetter().constructAliasManager(config); - + taskManager.rescheduleTasks(); } 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 a2f9800..4403db5 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -19,7 +19,7 @@ import java.util.concurrent.ExecutionException; public class QueueManagerImpl implements QueueManager { - private List servers; + private List servers = new ArrayList<>(); private final QueueMain main; private final Messages msgs; @@ -130,6 +130,9 @@ public class QueueManagerImpl implements QueueManager { ); } + if(!server.isJoinable(player)) { + sendMessage(queuePlayer); + } main.getPlatformMethods().sendJoinQueueChannelMessages(server, queuePlayer); return true; } @@ -272,10 +275,15 @@ public class QueueManagerImpl implements QueueManager { @Override public void sendMessages() { - for(QueueServer server : servers) { - for(QueuePlayer queuePlayer : server.getQueue()) { - sendMessage(queuePlayer); + if(servers == null) return; + try { + for(QueueServer server : servers) { + for(QueuePlayer queuePlayer : server.getQueue()) { + sendMessage(queuePlayer); + } } + } catch (Exception e) { + e.printStackTrace(); } } @@ -289,7 +297,7 @@ public class QueueManagerImpl implements QueueManager { int pos = queuePlayer.getPosition(); int len = server.getQueue().size(); - if(server.isJoinable(player)) { + if(!server.isJoinable(player)) { String status = server.getStatusString(player); if(msgs.getString("status.offline.base").isEmpty()) return; @@ -312,6 +320,17 @@ public class QueueManagerImpl implements QueueManager { } } + @Override + public void updateServers() { + try { + for(QueueServer server : servers) { + server.updatePing(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + @Override public QueueServer findServer(String name) { for(QueueServer server : servers) { @@ -360,22 +379,30 @@ public class QueueManagerImpl implements QueueManager { player.sendMessage(msgs.getComponent("status.sending-now", "SERVER:"+server.getAlias())); player.connect(selected); } - return; + continue; } QueuePlayer nextQueuePlayer = server.getQueue().get(0); AdaptedPlayer nextPlayer = nextQueuePlayer.getPlayer(); + // If the first person int the queue is offline or already in the server, find the next online player in the queue int i = 0; while((nextPlayer == null || server.getServerNames().contains(nextPlayer.getServerName())) && i < server.getQueue().size()) { if(nextPlayer != null) { // Remove them if they are already in the server server.removePlayer(nextQueuePlayer); + if(server.getQueue().size() > i) { + nextQueuePlayer = server.getQueue().get(i); + nextPlayer = nextQueuePlayer.getPlayer(); + } else { + nextPlayer = null; + break; + } } else { i++; + nextQueuePlayer = server.getQueue().get(i); + nextPlayer = nextQueuePlayer.getPlayer(); } - nextQueuePlayer = server.getQueue().get(i); - nextPlayer = nextQueuePlayer.getPlayer(); } if(nextPlayer == null) continue; // None of the players in the queue are online @@ -388,7 +415,6 @@ public class QueueManagerImpl implements QueueManager { if(server.isPaused() && !nextPlayer.hasPermission("ajqueue.bypasspaused")) continue; } else if(server.isPaused()) { continue; } - int tries = sendingAttempts.get(nextQueuePlayer) == null ? 0 : sendingAttempts.get(nextQueuePlayer); int maxTries = main.getConfig().getInt("max-tries"); if(tries >= maxTries && maxTries > 0) { diff --git a/common/src/main/java/us/ajg0702/queue/common/TaskManager.java b/common/src/main/java/us/ajg0702/queue/common/TaskManager.java new file mode 100644 index 0000000..5d636d6 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/common/TaskManager.java @@ -0,0 +1,123 @@ +package us.ajg0702.queue.common; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +public class TaskManager { + + ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + ScheduledExecutorService updateExecutor = Executors.newScheduledThreadPool(1); + + QueueMain main; + public TaskManager(QueueMain main) { + this.main = main; + } + + public String taskStatus() { + List> tasks = Arrays.asList(sendTask, updateTask, messageTask, actionBarTask, queueEventTask, reloadServerTask); + StringBuilder sb = new StringBuilder(); + for(ScheduledFuture task : tasks) { + sb.append(task == null ? "null" : task.isDone() ? "canceled/done" : "running"); + sb.append("\n"); + } + return sb.toString(); + } + + ScheduledFuture sendTask; + ScheduledFuture updateTask; + ScheduledFuture messageTask; + ScheduledFuture actionBarTask; + ScheduledFuture queueEventTask; + ScheduledFuture reloadServerTask; + public void rescheduleTasks() { + cancelTasks(); + + sendTask = scheduleAtFixedRate( + main.getQueueManager()::sendPlayers, + 0L, + (long) (main.getConfig().getDouble("wait-time")*1000L), + TimeUnit.MILLISECONDS + ); + + updateTask = scheduleAtFixedRate(updateExecutor, + main.getQueueManager()::updateServers, + 0L, + (long) (Math.max(main.getTimeBetweenPlayers(), 2)*1000L), + TimeUnit.MILLISECONDS + ); + + messageTask = scheduleAtFixedRate( + main.getQueueManager()::sendMessages, + 0L, + main.getConfig().getInt("message-time"), + TimeUnit.SECONDS + ); + + actionBarTask = scheduleAtFixedRate( + main.getQueueManager()::sendActionBars, + 0L, + 2L, + TimeUnit.SECONDS + ); + + queueEventTask = scheduleAtFixedRate( + main.getQueueManager()::sendQueueEvents, + 0L, + 2L, + TimeUnit.SECONDS + ); + + if(main.getConfig().getInt("reload-servers-interval") > 0) { + reloadServerTask = scheduleAtFixedRate( + main.getQueueManager()::reloadServers, + 0L, + main.getConfig().getInt("reload-servers-interval"), + TimeUnit.SECONDS + ); + } + + } + + public void cancelTasks() { + if(sendTask != null && !sendTask.isCancelled()) { + sendTask.cancel(false); + } + if(updateTask != null && !updateTask.isCancelled()) { + updateTask.cancel(false); + } + if(messageTask != null && !messageTask.isCancelled()) { + messageTask.cancel(false); + } + if(actionBarTask != null && !actionBarTask.isCancelled()) { + actionBarTask.cancel(false); + } + if(queueEventTask != null && !queueEventTask.isCancelled()) { + queueEventTask.cancel(false); + } + if(reloadServerTask != null && !reloadServerTask.isCancelled()) { + reloadServerTask.cancel(false); + reloadServerTask = null; + } + } + + private ScheduledFuture scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { + return scheduleAtFixedRate(executor, command, initialDelay, period, unit); + } + + + private ScheduledFuture scheduleAtFixedRate(ScheduledExecutorService executor, Runnable command, long initialDelay, long period, TimeUnit unit) { + return executor.scheduleAtFixedRate(() -> { + try { + command.run(); + } catch (Exception e) { + System.out.println("An error ocurred while running an ajQueue task"); + e.printStackTrace(); + } + }, initialDelay, period, unit); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java b/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java index 24e27de..b21765f 100644 --- a/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java @@ -28,6 +28,7 @@ public class QueuePlayerImpl implements QueuePlayer { @Override public UUID getUniqueId() { + if(uuid == null) throw new IllegalStateException("Why is my UUID null??"); return uuid; } diff --git a/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java b/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java index c24e9b4..2e036ff 100644 --- a/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java @@ -117,9 +117,13 @@ public class QueueServerImpl implements QueueServer { ping = futurePing.get(5, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { if(main.getConfig().getBoolean("pinger-debug")) { - main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] sending ping"); + main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] offline:"); + e.printStackTrace(); } } + if(ping != null && main.getConfig().getBoolean("pinger-debug")) { + main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] online. motd: "+ping.getPlainDescription()+" players: "+ping.getPlayerCount()+"/"+ping.getMaxPlayers()); + } pings.put(server, ping); i++; @@ -297,11 +301,18 @@ public class QueueServerImpl implements QueueServer { } @Override - public QueuePlayer findPlayer(AdaptedPlayer player) { + public synchronized QueuePlayer findPlayer(AdaptedPlayer player) { for(QueuePlayer queuePlayer : queue) { AdaptedPlayer queuedPlayer = queuePlayer.getPlayer(); if(queuedPlayer == null) continue; - if(queuedPlayer.getUniqueId().equals(player.getUniqueId())) { + if( + queuedPlayer + .getUniqueId() + .equals( + player + .getUniqueId() + ) + ) { return queuePlayer; } } diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 318af36..319edb8 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Dont touch this number please -config-version: 21 +config-version: 22 # The time the server will wait between sending people in the queue # Default: 5 @@ -171,4 +171,9 @@ auto-add-to-queue-on-kick-delay: 1 # This works on contains, so you dont have to include the whole kick message, just a few words. auto-add-kick-reasons: - "restarting" - - "closed" \ No newline at end of file + - "closed" + +# Should we enable the server command being a queue command? +# This may require extra setup on bungeecord. See the wiki: +# https://wiki.ajg0702.us/ajqueue/setup/replacing-server-command +enable-server-command: false \ No newline at end of file diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java index 260b357..625232f 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java @@ -9,6 +9,8 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; import us.ajg0702.queue.commands.BaseCommand; import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand; +import us.ajg0702.queue.commands.commands.listqueues.ListCommand; +import us.ajg0702.queue.commands.commands.manage.ManageCommand; import us.ajg0702.queue.commands.commands.queue.QueueCommand; import us.ajg0702.queue.common.QueueMain; import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand; @@ -59,7 +61,9 @@ public class VelocityQueue { List commands = Arrays.asList( new QueueCommand(main), - new LeaveCommand(main) + new LeaveCommand(main), + new ListCommand(main), + new ManageCommand(main) ); for(BaseCommand command : commands) { diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java index 343def1..4e9cfcb 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java @@ -1,11 +1,11 @@ package us.ajg0702.queue.platforms.velocity.players; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import us.ajg0702.queue.api.players.AdaptedPlayer; import us.ajg0702.queue.api.server.AdaptedServer; @@ -27,6 +27,7 @@ public class VelocityPlayer implements AdaptedPlayer, Audience { @Override public void sendMessage(Component message) { + if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return; handle.sendMessage(message); } diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServerPing.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServerPing.java index 402dc8e..762eabd 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServerPing.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServerPing.java @@ -27,14 +27,14 @@ public class VelocityServerPing implements AdaptedServerPing { @Override public int getPlayerCount() { Optional players = handle.getPlayers(); - if(players.isPresent()) return 0; + if(!players.isPresent()) return 0; return players.get().getOnline(); } @Override public int getMaxPlayers() { Optional players = handle.getPlayers(); - if(players.isPresent()) return 0; + if(!players.isPresent()) return 0; return players.get().getMax(); }