Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-27 03:12:37 +01:00
Added suggestions to a lot of factory-related commands
Dieser Commit ist enthalten in:
Ursprung
7b47d9a945
Commit
a3ffb91917
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.command.argument;
|
package com.sk89q.worldedit.command.argument;
|
||||||
|
|
||||||
|
import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix;
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
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.InjectedValueAccess;
|
||||||
import org.enginehub.piston.inject.Key;
|
import org.enginehub.piston.inject.Key;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class FactoryConverter<T> implements ArgumentConverter<T> {
|
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
|
@Override
|
||||||
public Component describeAcceptableArguments() {
|
public Component describeAcceptableArguments() {
|
||||||
return TextComponent.of("any " + description);
|
return TextComponent.of("any " + description);
|
||||||
|
@ -52,6 +52,7 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses block input strings.
|
* Parses block input strings.
|
||||||
@ -199,6 +200,12 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
return blockStates;
|
return blockStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
// TODO Include states
|
||||||
|
return BlockType.REGISTRY.keySet().stream();
|
||||||
|
}
|
||||||
|
|
||||||
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
||||||
BlockType blockType = null;
|
BlockType blockType = null;
|
||||||
Map<Property<?>, Object> blockStates = new HashMap<>();
|
Map<Property<?>, Object> blockStates = new HashMap<>();
|
||||||
|
@ -28,7 +28,11 @@ import com.sk89q.worldedit.world.item.ItemType;
|
|||||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class DefaultItemParser extends InputParser<BaseItem> {
|
public class DefaultItemParser extends InputParser<BaseItem> {
|
||||||
|
|
||||||
@ -36,6 +40,11 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
|||||||
super(worldEdit);
|
super(worldEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
return ItemType.REGISTRY.keySet().stream();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
|
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||||
BaseItem item = null;
|
BaseItem item = null;
|
||||||
|
@ -36,6 +36,7 @@ import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class BiomeMaskParser extends InputParser<Mask> {
|
public class BiomeMaskParser extends InputParser<Mask> {
|
||||||
|
|
||||||
@ -43,6 +44,11 @@ public class BiomeMaskParser extends InputParser<Mask> {
|
|||||||
super(worldEdit);
|
super(worldEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
return BiomeType.REGISTRY.keySet().stream().map(biomeType -> "$" + biomeType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||||
if (!input.startsWith("$")) {
|
if (!input.startsWith("$")) {
|
||||||
|
@ -29,6 +29,7 @@ import com.sk89q.worldedit.session.request.RequestExtent;
|
|||||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class BlockCategoryMaskParser extends InputParser<Mask> {
|
public class BlockCategoryMaskParser extends InputParser<Mask> {
|
||||||
|
|
||||||
@ -36,6 +37,11 @@ public class BlockCategoryMaskParser extends InputParser<Mask> {
|
|||||||
super(worldEdit);
|
super(worldEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||||
if (!input.startsWith("##")) {
|
if (!input.startsWith("##")) {
|
||||||
|
@ -28,8 +28,10 @@ import com.sk89q.worldedit.function.mask.Mask;
|
|||||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||||
import com.sk89q.worldedit.session.request.RequestExtent;
|
import com.sk89q.worldedit.session.request.RequestExtent;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses mask input strings.
|
* Parses mask input strings.
|
||||||
@ -40,6 +42,11 @@ public class BlocksMaskParser extends InputParser<Mask> {
|
|||||||
super(worldEdit);
|
super(worldEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
return worldEdit.getBlockFactory().getSuggestions();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mask parseFromInput(String component, ParserContext context) throws InputParseException {
|
public Mask parseFromInput(String component, ParserContext context) throws InputParseException {
|
||||||
ParserContext tempContext = new ParserContext(context);
|
ParserContext tempContext = new ParserContext(context);
|
||||||
|
@ -52,8 +52,8 @@ public class ExpressionMaskParser extends InputParser<Mask> {
|
|||||||
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
|
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
|
||||||
new RequestExtent(), Vector3.ONE, Vector3.ZERO);
|
new RequestExtent(), Vector3.ONE, Vector3.ZERO);
|
||||||
exp.setEnvironment(env);
|
exp.setEnvironment(env);
|
||||||
if (context.getActor() instanceof SessionOwner) {
|
if (context.getActor() != null) {
|
||||||
SessionOwner owner = (SessionOwner) context.getActor();
|
SessionOwner owner = context.getActor();
|
||||||
IntSupplier timeout = () -> WorldEdit.getInstance().getSessionManager().get(owner).getTimeout();
|
IntSupplier timeout = () -> WorldEdit.getInstance().getSessionManager().get(owner).getTimeout();
|
||||||
return new ExpressionMask(exp, timeout);
|
return new ExpressionMask(exp, timeout);
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,9 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
|||||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||||
|
|
||||||
@ -41,8 +40,8 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions() {
|
public Stream<String> getSuggestions() {
|
||||||
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str).collect(Collectors.toList());
|
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.sk89q.worldedit.EmptyClipboardException;
|
import com.sk89q.worldedit.EmptyClipboardException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
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.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ClipboardPatternParser extends InputParser<Pattern> {
|
public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||||
|
|
||||||
@ -41,8 +40,8 @@ public class ClipboardPatternParser extends InputParser<Pattern> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions() {
|
public Stream<String> getSuggestions() {
|
||||||
return Lists.newArrayList("#clipboard", "#copy");
|
return Stream.of("#clipboard", "#copy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,9 @@ import com.sk89q.worldedit.extension.input.ParserContext;
|
|||||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
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> {
|
public class SingleBlockPatternParser extends InputParser<Pattern> {
|
||||||
|
|
||||||
@ -32,6 +35,11 @@ public class SingleBlockPatternParser extends InputParser<Pattern> {
|
|||||||
super(worldEdit);
|
super(worldEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
return worldEdit.getBlockFactory().getSuggestions();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||||
return new BlockPattern(worldEdit.getBlockFactory().parseFromInput(input, context));
|
return new BlockPattern(worldEdit.getBlockFactory().parseFromInput(input, context));
|
||||||
|
@ -28,5 +28,5 @@ public interface ExtentPattern extends Pattern {
|
|||||||
*
|
*
|
||||||
* @return the extent for this pattern
|
* @return the extent for this pattern
|
||||||
*/
|
*/
|
||||||
public Extent getExtent();
|
Extent getExtent();
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,11 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
|
|||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract implementation of a factory for internal usage.
|
* 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 + "'");
|
throw new NoMatchException("No match for '" + input + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream<String> getSuggestions() {
|
||||||
|
return parsers.stream().flatMap(InputParser::getSuggestions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers an InputParser to this factory
|
* Registers an InputParser to this factory
|
||||||
*
|
*
|
||||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.input.ParserContext;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Input parser interface for {@link AbstractFactory}.
|
* 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;
|
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() {
|
public Stream<String> getSuggestions() {
|
||||||
return Collections.emptyList();
|
return Stream.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.input.InputParseException;
|
|||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An input parser that only performs a single function from aliases.
|
* An input parser that only performs a single function from aliases.
|
||||||
@ -65,7 +66,7 @@ public abstract class SimpleInputParser<E> extends InputParser<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions() {
|
public Stream<String> getSuggestions() {
|
||||||
return Lists.newArrayList(getPrimaryMatcher());
|
return Stream.of(getPrimaryMatcher());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren