From 5165185ff192da75ac7d576fb152fbead32df27c Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 12 Jul 2021 20:37:09 -0700 Subject: [PATCH] more progress --- .../us/ajg0702/queue/api/PlatformMethods.java | 2 + .../commands/manage/ManageCommand.java | 5 +- .../queue/commands/commands/manage/Pause.java | 77 +++++++++++++++++++ .../commands/commands/manage/Version.java | 50 ++++++++++++ ...thodImpl.java => PlatformMethodsImpl.java} | 15 +++- .../platforms/velocity/VelocityQueue.java | 2 +- .../velocity/commands/VelocityCommand.java | 8 +- 7 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/manage/Pause.java create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java rename platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/{PlatformMethodImpl.java => PlatformMethodsImpl.java} (67%) 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 8bc7c98..02705bd 100644 --- a/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java +++ b/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java @@ -31,4 +31,6 @@ public interface PlatformMethods { */ AdaptedPlayer senderToPlayer(ICommandSender sender); + String getPluginVersion(); + } 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 b2475cc..e0efd7a 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 @@ -22,6 +22,8 @@ public class ManageCommand extends BaseCommand { addSubCommand(new Reload(main)); addSubCommand(new Tasks(main)); + addSubCommand(new Version(main)); + addSubCommand(new Pause(main)); } @@ -72,12 +74,13 @@ public class ManageCommand extends BaseCommand { @Override public List autoComplete(ICommandSender sender, String[] args) { - if(args.length > 0) { + if(args.length > 1) { 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)); } } + return new ArrayList<>(); } List commands = new ArrayList<>(); for(ISubCommand subCommand : subCommands) { diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Pause.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Pause.java new file mode 100644 index 0000000..d25575c --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Pause.java @@ -0,0 +1,77 @@ +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.queues.QueueServer; +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.Arrays; +import java.util.List; + +public class Pause extends SubCommand { + + final QueueMain main; + public Pause(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "pause"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.pause"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + + if(args.length < 1) { + sender.sendMessage(getMessages().getComponent("commands.pause.more-args")); + return; + } + + QueueServer server = main.getQueueManager().findServer(args[0]); + if(server == null) { + sender.sendMessage(getMessages().getComponent("commands.pause.no-server", "SERVER:"+args[1])); + return; + } + if(args.length == 1) { + server.setPaused(!server.isPaused()); + } else { + server.setPaused(args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")); + } + sender.sendMessage(getMessages().getComponent("commands.pause.success", + "SERVER:"+server.getName(), + "PAUSED:"+getMessages().getString("commands.pause.paused."+server.isPaused()) + )); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + if(args.length == 1) { + return main.getQueueManager().getServerNames(); + } + if(args.length == 2) { + return Arrays.asList("on", "off", "true", "false"); + } + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java new file mode 100644 index 0000000..ab3311b --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java @@ -0,0 +1,50 @@ +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.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.List; + +public class Version extends SubCommand { + + final QueueMain main; + public Version(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "version"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.version"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + sender.sendMessage(Component.text(main.getPlatformMethods().getPluginVersion())); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodImpl.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java similarity index 67% rename from platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodImpl.java rename to platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java index a7bc869..5740154 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodImpl.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java @@ -1,5 +1,6 @@ package us.ajg0702.queue.platforms.velocity; +import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import net.kyori.adventure.text.Component; @@ -10,14 +11,15 @@ import us.ajg0702.queue.api.players.QueuePlayer; import us.ajg0702.queue.api.queues.QueueServer; import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer; +import java.util.Optional; import java.util.logging.Logger; -public class PlatformMethodImpl implements PlatformMethods { +public class PlatformMethodsImpl implements PlatformMethods { final ProxyServer proxyServer; final Logger logger; - public PlatformMethodImpl(ProxyServer proxyServer, Logger logger) { + public PlatformMethodsImpl(ProxyServer proxyServer, Logger logger) { this.proxyServer = proxyServer; this.logger = logger; } @@ -38,4 +40,13 @@ public class PlatformMethodImpl implements PlatformMethods { public AdaptedPlayer senderToPlayer(ICommandSender sender) { return new VelocityPlayer((Player) sender.getHandle()); } + + @Override + public String getPluginVersion() { + Optional plugin = proxyServer.getPluginManager().getPlugin("ajqueue"); + if(plugin.isEmpty()) return "?E"; + Optional version = plugin.get().getDescription().getVersion(); + if(version.isEmpty()) return "?V"; + return version.get(); + } } 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 ad1db86..77c2039 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 @@ -51,7 +51,7 @@ public class VelocityQueue { public void onProxyInit(ProxyInitializeEvent e) { main = new QueueMain( logger, - new PlatformMethodImpl(proxyServer, logger), + new PlatformMethodsImpl(proxyServer, logger), dataFolder ); main.setServerBuilder(new ServerBuilderImpl(main, proxyServer)); diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java index 4e81c56..c8d21f1 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java @@ -4,6 +4,8 @@ import com.velocitypowered.api.command.RawCommand; import us.ajg0702.queue.commands.BaseCommand; import us.ajg0702.queue.common.QueueMain; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class VelocityCommand implements RawCommand { @@ -23,7 +25,11 @@ public class VelocityCommand implements RawCommand { @Override public List suggest(final Invocation invocation) { - return command.autoComplete(new VelocitySender(invocation.source()), invocation.arguments().split(" ")); + List args = new ArrayList<>(Arrays.asList(invocation.arguments().split(" "))); + if(invocation.arguments().length() > 0 &&invocation.arguments().charAt(invocation.arguments().length()-1) == ' ') { + args.add(" "); + } + return command.autoComplete(new VelocitySender(invocation.source()), args.toArray(new String[0])); } @Override