diff --git a/Core/src/main/java/com/plotsquared/core/command/Biome.java b/Core/src/main/java/com/plotsquared/core/command/Biome.java index c7df94a48..4af7fdfd3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Biome.java +++ b/Core/src/main/java/com/plotsquared/core/command/Biome.java @@ -30,9 +30,14 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.StringMan; +import com.sk89q.worldedit.command.util.SuggestionHelper; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; +import java.util.Collection; +import java.util.Locale; +import java.util.stream.Collectors; + @CommandDeclaration(command = "setbiome", permission = "plots.set.biome", description = "Set the plot biome", @@ -68,4 +73,13 @@ public class Biome extends SetCommand { }); return true; } + + @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { + return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, args[0]) + .map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", "")) + .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) + .map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {}) + .collect(Collectors.toList()); + } + } 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 f3503b82d..a87f2eebc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -42,9 +42,12 @@ import com.sk89q.worldedit.world.block.BlockTypes; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.stream.Collectors; +import java.util.stream.Stream; @CommandDeclaration(command = "set", description = "Set a plot value", @@ -136,6 +139,16 @@ public class Set extends SubCommand { } return false; } + + @Override + public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { + return PatternUtil.getSuggestions(player, StringMan.join(args, ",").trim()) + .stream() + .map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", "")) + .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) + .map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {}) + .collect(Collectors.toList()); + } }; } @@ -177,4 +190,38 @@ public class Set extends SubCommand { } return noArgs(player); } + + @Override public Collection tab(final PlotPlayer player, final String[] args, final 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()); + } else if (args.length > 1) { + // Additional checks + Plot plot = player.getCurrentPlot(); + if (plot == null) { + return new ArrayList<>(); + } + + final String[] newArgs = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, newArgs.length); + + final Command cmd = MainCommand.getInstance().getCommand("set" + args[0]); + if (cmd != null) { + if (!Permissions.hasPermission(player, cmd.getPermission(), true)) { + return new ArrayList<>(); + } + return cmd.tab(player, newArgs, space); + } + + // components + HashSet components = new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId()))); + if (components.contains(args[0].toLowerCase())) { + return this.component.tab(player, newArgs, space); + } + } + return tabOf(player, args, space); + } } diff --git a/Core/src/main/java/com/plotsquared/core/util/PatternUtil.java b/Core/src/main/java/com/plotsquared/core/util/PatternUtil.java index bbcfbbd52..ee390cc04 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PatternUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/PatternUtil.java @@ -43,6 +43,9 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.List; + public class PatternUtil { public static BaseBlock apply(@NotNull Pattern pattern, int x, int y, int z) { @@ -59,6 +62,14 @@ public class PatternUtil { return parse(plotPlayer, input, true); } + public static List getSuggestions(PlotPlayer plotPlayer, String input) { + try { + return WorldEdit.getInstance().getPatternFactory().getSuggestions(input); + } catch (final Exception ignored) { + } + return new ArrayList<>(); + } + public static Pattern parse(PlotPlayer plotPlayer, String input, boolean allowLegacy) { ParserContext context = new ParserContext(); if (plotPlayer != null) {