From 02698b3a0e7fb76e1f05d03dbf59947ecd00de56 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Thu, 8 Oct 2020 20:42:17 +0200 Subject: [PATCH] Fix plot grant tab completion --- .../com/plotsquared/core/command/Grant.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Grant.java b/Core/src/main/java/com/plotsquared/core/command/Grant.java index a80ed4a49..aaea5a68a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Grant.java +++ b/Core/src/main/java/com/plotsquared/core/command/Grant.java @@ -35,19 +35,21 @@ import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.PlayerManager; +import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; import net.kyori.adventure.text.minimessage.Template; import com.plotsquared.core.uuid.UUIDMapping; -import java.util.Collection; -import java.util.Locale; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import java.util.stream.Stream; @CommandDeclaration(command = "grant", category = CommandCategory.CLAIMING, @@ -139,10 +141,22 @@ public class Grant extends Command { sendUsage(player); return CompletableFuture.completedFuture(true); } - @Override public Collection tab(final PlotPlayer player, String[] args, boolean space) { - return Stream.of("check", "add") - .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) - .map(value -> new Command(null, false, value, "plots.grant", RequiredType.NONE, null) { - }).collect(Collectors.toList()); + @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.grant.add")) { + completions.add("add"); + } + if (Permissions.hasPermission(player, "plots.grant.check")) { + completions.add("check"); + } + 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.grant") && args[0].length() > 0) { + commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList())); + } + return commands; + } return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList()); } }