From 6f0512c18c0c428880c3b00bb2ff4bb0206cb51f Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Thu, 8 Oct 2020 20:16:29 +0200 Subject: [PATCH] Fix plot set tab completions --- .../com/plotsquared/core/command/Set.java | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index 725d07667..3090ed3c5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -45,6 +45,8 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import java.util.Collections; +import java.util.LinkedList; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; @@ -213,15 +215,51 @@ public class Set extends SubCommand { } @Override - public Collection tab(final PlotPlayer player, final String[] args, - final boolean space) { + public Collection tab(final PlotPlayer player, String[] args, boolean space) { if (args.length == 1) { - return Stream - .of("biome", "alias", "home", "main", "floor", "air", "all", "border", "wall", - "outline", "middle") - .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) - .map(value -> new Command(null, false, value, "", RequiredType.NONE, null) { - }).collect(Collectors.toList()); + final List completions = new LinkedList<>(); + + if (Permissions.hasPermission(player, "plots.set.biome")) { + completions.add("biome"); + } + if (Permissions.hasPermission(player, "plots.set.alias")) { + completions.add("alias"); + } + if (Permissions.hasPermission(player, "plots.set.home")) { + completions.add("home"); + } + if (Permissions.hasPermission(player, "plots.set.main")) { + completions.add("main"); + } + if (Permissions.hasPermission(player, "plots.set.floor")) { + completions.add("floor"); + } + if (Permissions.hasPermission(player, "plots.set.air")) { + completions.add("air"); + } + if (Permissions.hasPermission(player, "plots.set.all")) { + completions.add("all"); + } + if (Permissions.hasPermission(player, "plots.set.border")) { + completions.add("border"); + } + if (Permissions.hasPermission(player, "plots.set.wall")) { + completions.add("wall"); + } + if (Permissions.hasPermission(player, "plots.set.outline")) { + completions.add("outline"); + } + if (Permissions.hasPermission(player, "plots.set.middle")) { + completions.add("middle"); + } + final List commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase())) + .map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.APPEARANCE) { + }).collect(Collectors.toCollection(LinkedList::new)); + + if (Permissions.hasPermission(player, "plots.set") && args[0].length() > 0) { + commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList())); + } + return commands; } else if (args.length > 1) { // Additional checks Plot plot = player.getCurrentPlot();