mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
(Complex) command suggestions for /plot set
This commit is contained in:
parent
df01f9bea7
commit
8944be5319
@ -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<Command> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Command> 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<Command> 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<String> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user