From 0745b03271bd8d5c9a15bdd0319054384c5c2418 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Thu, 19 Nov 2020 17:00:21 +0100 Subject: [PATCH] Add tab completion for /plot cluster --- .../com/plotsquared/core/command/Cluster.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index 83105d935..0a8b829d3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -29,7 +29,6 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.Caption; -import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.TeleportCause; @@ -41,13 +40,14 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotCluster; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.Permissions; +import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.query.PlotQuery; import net.kyori.adventure.text.minimessage.Template; -import java.util.HashSet; +import java.util.*; import java.util.Set; -import java.util.UUID; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; @CommandDeclaration(command = "cluster", aliases = "clusters", @@ -814,4 +814,51 @@ public class Cluster extends SubCommand { player.sendMessage(TranslatableCaption.of("cluster.cluster_available_args")); return false; } + @Override + public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { + if (args.length == 1) { + final List completions = new LinkedList<>(); + if (Permissions.hasPermission(player, "plots.cluster.list")) { + completions.add("list"); + } + if (Permissions.hasPermission(player, "plots.cluster.create")) { + completions.add("create"); + } + if (Permissions.hasPermission(player, "plots.cluster.delete")) { + completions.add("delete"); + } + if (Permissions.hasPermission(player, "plots.cluster.resize")) { + completions.add("resize"); + } + if (Permissions.hasPermission(player, "plots.cluster.invite")) { + completions.add("invite"); + } + if (Permissions.hasPermission(player, "plots.cluster.kick")) { + completions.add("kick"); + } + if (Permissions.hasPermission(player, "plots.cluster.leave")) { + completions.add("leave"); + } + if (Permissions.hasPermission(player, "plots.cluster.members")) { + completions.add("members"); + } + if (Permissions.hasPermission(player, "plots.cluster.info")) { + completions.add("info"); + } + if (Permissions.hasPermission(player, "plots.cluster.tp")) { + completions.add("tp"); + } + if (Permissions.hasPermission(player, "plots.cluster.sethome")) { + completions.add("sethome"); + } + final List commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase())) + .map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) { + }).collect(Collectors.toCollection(LinkedList::new)); + if (Permissions.hasPermission(player, "plots.cluster") && args[0].length() > 0) { + commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList())); + } + return commands; + } + return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList()); + } }