mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-10 06:58:34 +00:00
Add comprehensive suggestions to many commands.
All patterns now have suggestions, including recursive patterns. Suggestions will suggest blocks and block states. All masks now have suggestions, though mask intersections are not yet supported due to issues with quotes strings. EntityRemover and ItemFactory now also have completions, as well as all RegistryConverters (though I am unsure how many are actually used). Also use paper's AsyncTabComplete event, if available.
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
@ -41,7 +42,7 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str);
|
||||
return SuggestionHelper.getBlockCategorySuggestions(input, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,6 +31,7 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||
@ -41,7 +42,27 @@ public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return Stream.of("#clipboard", "#copy");
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("#clipoard");
|
||||
}
|
||||
String[] offsetParts = input.split("@", 2);
|
||||
String firstLower = offsetParts[0].toLowerCase(Locale.ROOT);
|
||||
final boolean isClip = "#clipboard".startsWith(firstLower);
|
||||
final boolean isCopy = "#copy".startsWith(firstLower);
|
||||
if (isClip || isCopy) {
|
||||
if (offsetParts.length == 2) {
|
||||
String coords = offsetParts[1];
|
||||
if (coords.isEmpty()) {
|
||||
return Stream.of(input + "[x,y,z]");
|
||||
}
|
||||
} else {
|
||||
if (isClip) {
|
||||
return Stream.of("#clipboard", "#clipboard@[x,y,z]");
|
||||
}
|
||||
return Stream.of("#copy", "#copy@[x,y,z]");
|
||||
}
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomPatternParser extends InputParser<Pattern> {
|
||||
|
||||
@ -35,12 +36,35 @@ public class RandomPatternParser extends InputParser<Pattern> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
String[] splits = input.split(",", -1);
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']', true);
|
||||
if (patterns.size() == 1) {
|
||||
return Stream.empty();
|
||||
}
|
||||
// get suggestions for the last token only
|
||||
String token = patterns.get(patterns.size() - 1);
|
||||
String previous = String.join(",", patterns.subList(0, patterns.size() - 1));
|
||||
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
|
||||
String[] p = token.split("%");
|
||||
|
||||
if (p.length < 2) {
|
||||
return Stream.empty();
|
||||
} else {
|
||||
token = p[1];
|
||||
}
|
||||
}
|
||||
final List<String> innerSuggestions = worldEdit.getPatternFactory().getSuggestions(token);
|
||||
return innerSuggestions.stream().map(s -> previous + "," + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
RandomPattern randomPattern = new RandomPattern();
|
||||
|
||||
String[] splits = input.split(",");
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']');
|
||||
String[] splits = input.split(",", -1);
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']', true);
|
||||
if (patterns.size() == 1) {
|
||||
return null; // let a 'single'-pattern parser handle it
|
||||
}
|
||||
|
@ -29,11 +29,25 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomStatePatternParser extends InputParser<Pattern> {
|
||||
public RandomStatePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("*");
|
||||
}
|
||||
if (!input.startsWith("*")) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
return worldEdit.getBlockFactory().getSuggestions(input.substring(1)).stream().map(s -> "*" + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("*")) {
|
||||
|
@ -25,7 +25,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -20,9 +20,8 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -32,10 +31,9 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.StateApplyingPattern;
|
||||
import com.sk89q.worldedit.function.pattern.TypeApplyingPattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class TypeOrStateApplyingPatternParser extends InputParser<Pattern> {
|
||||
@ -44,6 +42,30 @@ public class TypeOrStateApplyingPatternParser extends InputParser<Pattern> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("^");
|
||||
}
|
||||
if (!input.startsWith("^")) {
|
||||
return Stream.empty();
|
||||
}
|
||||
input = input.substring(1);
|
||||
|
||||
String[] parts = input.split("\\[", 2);
|
||||
String type = parts[0];
|
||||
|
||||
if (parts.length == 1) {
|
||||
return worldEdit.getBlockFactory().getSuggestions(input).stream().map(s -> "^" + s);
|
||||
} else {
|
||||
if (type.isEmpty()) {
|
||||
return Stream.empty(); // without knowing a type, we can't really suggest states
|
||||
} else {
|
||||
return SuggestionHelper.getBlockPropertySuggestions(type, parts[1]).map(s -> "^" + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("^")) {
|
||||
|
Reference in New Issue
Block a user