3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

Added suggestions to a lot of factory-related commands

Dieser Commit ist enthalten in:
Matthew Miller 2019-05-18 16:47:08 +10:00
Ursprung 7b47d9a945
Commit a3ffb91917
14 geänderte Dateien mit 75 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.command.argument;
import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
@ -41,6 +43,7 @@ import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
import java.util.List;
import java.util.function.Function;
public class FactoryConverter<T> implements ArgumentConverter<T> {
@ -92,6 +95,11 @@ public class FactoryConverter<T> implements ArgumentConverter<T> {
}
}
@Override
public List<String> getSuggestions(String input) {
return limitByPrefix(factoryExtractor.apply(worldEdit).getSuggestions(), input);
}
@Override
public Component describeAcceptableArguments() {
return TextComponent.of("any " + description);

Datei anzeigen

@ -52,6 +52,7 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
/**
* Parses block input strings.
@ -199,6 +200,12 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
return blockStates;
}
@Override
public Stream<String> getSuggestions() {
// TODO Include states
return BlockType.REGISTRY.keySet().stream();
}
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
BlockType blockType = null;
Map<Property<?>, Object> blockStates = new HashMap<>();

Datei anzeigen

@ -28,7 +28,11 @@ import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class DefaultItemParser extends InputParser<BaseItem> {
@ -36,6 +40,11 @@ public class DefaultItemParser extends InputParser<BaseItem> {
super(worldEdit);
}
@Override
public Stream<String> getSuggestions() {
return ItemType.REGISTRY.keySet().stream();
}
@Override
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
BaseItem item = null;

Datei anzeigen

@ -36,6 +36,7 @@ import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;
public class BiomeMaskParser extends InputParser<Mask> {
@ -43,6 +44,11 @@ public class BiomeMaskParser extends InputParser<Mask> {
super(worldEdit);
}
@Override
public Stream<String> getSuggestions() {
return BiomeType.REGISTRY.keySet().stream().map(biomeType -> "$" + biomeType);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("$")) {

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.world.block.BlockCategory;
import java.util.Locale;
import java.util.stream.Stream;
public class BlockCategoryMaskParser extends InputParser<Mask> {
@ -36,6 +37,11 @@ public class BlockCategoryMaskParser extends InputParser<Mask> {
super(worldEdit);
}
@Override
public Stream<String> getSuggestions() {
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("##")) {

Datei anzeigen

@ -28,8 +28,10 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockCategory;
import java.util.Set;
import java.util.stream.Stream;
/**
* Parses mask input strings.
@ -40,6 +42,11 @@ public class BlocksMaskParser extends InputParser<Mask> {
super(worldEdit);
}
@Override
public Stream<String> getSuggestions() {
return worldEdit.getBlockFactory().getSuggestions();
}
@Override
public Mask parseFromInput(String component, ParserContext context) throws InputParseException {
ParserContext tempContext = new ParserContext(context);

Datei anzeigen

@ -52,8 +52,8 @@ public class ExpressionMaskParser extends InputParser<Mask> {
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
new RequestExtent(), Vector3.ONE, Vector3.ZERO);
exp.setEnvironment(env);
if (context.getActor() instanceof SessionOwner) {
SessionOwner owner = (SessionOwner) context.getActor();
if (context.getActor() != null) {
SessionOwner owner = context.getActor();
IntSupplier timeout = () -> WorldEdit.getInstance().getSessionManager().get(owner).getTimeout();
return new ExpressionMask(exp, timeout);
}

Datei anzeigen

@ -29,10 +29,9 @@ import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockType;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class BlockCategoryPatternParser extends InputParser<Pattern> {
@ -41,8 +40,8 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
}
@Override
public List<String> getSuggestions() {
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str).collect(Collectors.toList());
public Stream<String> getSuggestions() {
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str);
}
@Override

Datei anzeigen

@ -19,7 +19,6 @@
package com.sk89q.worldedit.extension.factory.parser.pattern;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
@ -32,7 +31,7 @@ import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder;
import java.util.List;
import java.util.stream.Stream;
public class ClipboardPatternParser extends InputParser<Pattern> {
@ -41,8 +40,8 @@ public class ClipboardPatternParser extends InputParser<Pattern> {
}
@Override
public List<String> getSuggestions() {
return Lists.newArrayList("#clipboard", "#copy");
public Stream<String> getSuggestions() {
return Stream.of("#clipboard", "#copy");
}
@Override

Datei anzeigen

@ -25,6 +25,9 @@ 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;
public class SingleBlockPatternParser extends InputParser<Pattern> {
@ -32,6 +35,11 @@ public class SingleBlockPatternParser extends InputParser<Pattern> {
super(worldEdit);
}
@Override
public Stream<String> getSuggestions() {
return worldEdit.getBlockFactory().getSuggestions();
}
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
return new BlockPattern(worldEdit.getBlockFactory().parseFromInput(input, context));

Datei anzeigen

@ -28,5 +28,5 @@ public interface ExtentPattern extends Pattern {
*
* @return the extent for this pattern
*/
public Extent getExtent();
Extent getExtent();
}

Datei anzeigen

@ -27,8 +27,11 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* An abstract implementation of a factory for internal usage.
@ -76,6 +79,10 @@ public abstract class AbstractFactory<E> {
throw new NoMatchException("No match for '" + input + "'");
}
public Stream<String> getSuggestions() {
return parsers.stream().flatMap(InputParser::getSuggestions);
}
/**
* Registers an InputParser to this factory
*

Datei anzeigen

@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
/**
* Input parser interface for {@link AbstractFactory}.
@ -43,11 +44,11 @@ public abstract class InputParser<E> {
public abstract E parseFromInput(String input, ParserContext context) throws InputParseException;
/**
* Gets a list of suggestions of input to this parser.
* Gets a stream of suggestions of input to this parser.
*
* @return a list of suggestions
* @return a stream of suggestions
*/
public List<String> getSuggestions() {
return Collections.emptyList();
public Stream<String> getSuggestions() {
return Stream.empty();
}
}

Datei anzeigen

@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.List;
import java.util.stream.Stream;
/**
* An input parser that only performs a single function from aliases.
@ -65,7 +66,7 @@ public abstract class SimpleInputParser<E> extends InputParser<E> {
}
@Override
public List<String> getSuggestions() {
return Lists.newArrayList(getPrimaryMatcher());
public Stream<String> getSuggestions() {
return Stream.of(getPrimaryMatcher());
}
}