mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 08:08:34 +00:00
Re-implement richer mask and transform parsing (#1223)
Co-authored-by: dordsor21 <dordsor21@gmail.com> Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
This commit is contained in:
@ -1,136 +0,0 @@
|
||||
// TODO: Ping @MattBDev to reimplement 2020-02-04
|
||||
//package com.sk89q.worldedit.extension.factory;
|
||||
//
|
||||
//import com.boydti.fawe.command.FaweParser;
|
||||
//import com.boydti.fawe.command.SuggestInputParseException;
|
||||
//import com.boydti.fawe.object.extent.MultiTransform;
|
||||
//import com.boydti.fawe.object.extent.RandomTransform;
|
||||
//import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
//import com.boydti.fawe.object.random.TrueRandom;
|
||||
//import com.boydti.fawe.util.StringMan;
|
||||
//import com.google.common.collect.Iterables;
|
||||
//import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
//import com.sk89q.worldedit.WorldEdit;
|
||||
////import com.sk89q.worldedit.command.TransformCommands;
|
||||
//import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
//import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
//import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
//import com.sk89q.worldedit.extension.platform.Actor;
|
||||
//import com.sk89q.worldedit.internal.expression.Expression;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
||||
//
|
||||
// public DefaultTransformParser(WorldEdit worldEdit) {
|
||||
// super(worldEdit, "transforms");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
// if (input.isEmpty()) return null;
|
||||
//
|
||||
// List<Double> unionChances = new ArrayList<>();
|
||||
// List<Double> intersectionChances = new ArrayList<>();
|
||||
//
|
||||
// List<ResettableExtent> intersection = new ArrayList<>();
|
||||
// List<ResettableExtent> union = new ArrayList<>();
|
||||
// final CommandLocals locals = new CommandLocals();
|
||||
// Actor actor = context != null ? context.getActor() : null;
|
||||
// if (actor != null) {
|
||||
// locals.put(Actor.class, actor);
|
||||
// }
|
||||
// try {
|
||||
// List<Map.Entry<ParseEntry, List<String>>> parsed = parse(input);
|
||||
// for (Map.Entry<ParseEntry, List<String>> entry : parsed) {
|
||||
// ParseEntry pe = entry.getKey();
|
||||
// String command = pe.input;
|
||||
// ResettableExtent transform;
|
||||
// double chance = 1;
|
||||
// if (command.isEmpty()) {
|
||||
// transform = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
// } else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// transform = parse(command + cmdArgs, context);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// throw new NoMatchException("See: //transforms");
|
||||
// }
|
||||
// if (transform == null) {
|
||||
// // Legacy syntax
|
||||
// int percentIndex = command.indexOf('%');
|
||||
// if (percentIndex != -1) { // Legacy percent pattern
|
||||
// chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
// command = command.substring(percentIndex + 1);
|
||||
// if (!entry.getValue().isEmpty()) {
|
||||
// if (!command.isEmpty()) command += " ";
|
||||
// command += StringMan.join(entry.getValue(), " ");
|
||||
// }
|
||||
// transform = parseFromInput(command, context);
|
||||
// } else {
|
||||
// throw new NoMatchException("See: //transforms");
|
||||
// }
|
||||
// }
|
||||
// if (pe.and) { // &
|
||||
// intersectionChances.add(chance);
|
||||
// intersection.add(transform);
|
||||
// } else {
|
||||
// if (!intersection.isEmpty()) {
|
||||
// if (intersection.size() == 1) {
|
||||
// throw new InputParseException("Error, floating &");
|
||||
// }
|
||||
// MultiTransform multi = new MultiTransform();
|
||||
// double total = 0;
|
||||
// for (int i = 0; i < intersection.size(); i++) {
|
||||
// Double value = intersectionChances.get(i);
|
||||
// total += value;
|
||||
// multi.add(intersection.get(i), value);
|
||||
// }
|
||||
// union.add(multi);
|
||||
// unionChances.add(total);
|
||||
// intersection.clear();
|
||||
// intersectionChances.clear();
|
||||
// }
|
||||
// unionChances.add(chance);
|
||||
// union.add(transform);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Throwable e) {
|
||||
// throw new InputParseException(e.getMessage(), e);
|
||||
// }
|
||||
// if (!intersection.isEmpty()) {
|
||||
// if (intersection.size() == 1) {
|
||||
// throw new InputParseException("Error, floating &");
|
||||
// }
|
||||
// MultiTransform multi = new MultiTransform();
|
||||
// double total = 0;
|
||||
// for (int i = 0; i < intersection.size(); i++) {
|
||||
// Double value = intersectionChances.get(i);
|
||||
// total += value;
|
||||
// multi.add(intersection.get(i), value);
|
||||
// }
|
||||
// union.add(multi);
|
||||
// unionChances.add(total);
|
||||
// intersection.clear();
|
||||
// intersectionChances.clear();
|
||||
// }
|
||||
// if (union.isEmpty()) {
|
||||
// throw new NoMatchException("See: //transforms");
|
||||
// } else if (union.size() == 1) {
|
||||
// return union.get(0);
|
||||
// } else {
|
||||
// RandomTransform random = new RandomTransform(new TrueRandom());
|
||||
// for (int i = 0; i < union.size(); i++) {
|
||||
// random.add(union.get(i), unionChances.get(i));
|
||||
// }
|
||||
// return random;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
@ -0,0 +1,144 @@
|
||||
package com.fastasyncworldedit.core.extension.factory;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.RichTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.Linear3DTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.LinearTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.OffsetTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.PatternTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.RandomTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.RotateTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.ScaleTransformParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.transform.SpreadTransformParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.RandomTransform;
|
||||
import com.fastasyncworldedit.core.math.random.TrueRandom;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TransformFactory extends AbstractFactory<ResettableExtent> {
|
||||
|
||||
private final RichTransformParser richTransformParser;
|
||||
|
||||
/**
|
||||
* Create a new factory.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public TransformFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit, new NullTransformParser(worldEdit));
|
||||
|
||||
richTransformParser = new RichTransformParser(worldEdit);
|
||||
|
||||
// split and parse each sub-transform
|
||||
register(new RandomTransformParser(worldEdit));
|
||||
|
||||
register(new OffsetTransformParser(worldEdit));
|
||||
register(new ScaleTransformParser(worldEdit));
|
||||
register(new RotateTransformParser(worldEdit));
|
||||
register(new SpreadTransformParser(worldEdit));
|
||||
register(new PatternTransformParser(worldEdit));
|
||||
register(new LinearTransformParser(worldEdit));
|
||||
register(new Linear3DTransformParser(worldEdit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
List<ResettableExtent> transforms = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ResettableExtent match = richTransformParser.parseFromInput(component, context);
|
||||
if (match != null) {
|
||||
transforms.add(match);
|
||||
continue;
|
||||
}
|
||||
parseFromParsers(context, transforms, component);
|
||||
}
|
||||
|
||||
return getResettableExtent(input, transforms);
|
||||
}
|
||||
|
||||
private void parseFromParsers(
|
||||
final ParserContext context,
|
||||
final List<ResettableExtent> transforms,
|
||||
final String component
|
||||
) {
|
||||
ResettableExtent match = null;
|
||||
for (InputParser<ResettableExtent> parser : getParsers()) {
|
||||
match = parser.parseFromInput(component, context);
|
||||
|
||||
if (match != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(component)));
|
||||
}
|
||||
transforms.add(match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a transform without considering parsing through the {@link RichTransformParser}, therefore not accepting
|
||||
* "richer" parsing where & and , are used. Exists to prevent stack overflows.
|
||||
*
|
||||
* @param input input string
|
||||
* @param context input context
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
public ResettableExtent parseWithoutRich(String input, ParserContext context) throws InputParseException {
|
||||
List<ResettableExtent> transforms = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parseFromParsers(context, transforms, component);
|
||||
}
|
||||
|
||||
return getResettableExtent(input, transforms);
|
||||
}
|
||||
|
||||
private ResettableExtent getResettableExtent(final String input, final List<ResettableExtent> transforms) {
|
||||
switch (transforms.size()) {
|
||||
case 0:
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
case 1:
|
||||
return transforms.get(0);
|
||||
default:
|
||||
RandomTransform randomTransform = new RandomTransform(new TrueRandom());
|
||||
for (ResettableExtent transform : transforms) {
|
||||
randomTransform.add(transform, 1d);
|
||||
}
|
||||
return randomTransform;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO is there a better default?
|
||||
private static final class NullTransformParser extends InputParser<ResettableExtent> {
|
||||
|
||||
private NullTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AliasedParser {
|
||||
|
||||
/**
|
||||
* The strings this parser matches.
|
||||
*
|
||||
* @return the matching aliases
|
||||
*/
|
||||
List<String> getMatchedAliases();
|
||||
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.util.StringMan;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class FaweParser<T> extends InputParser<T> implements AliasedParser {
|
||||
|
||||
protected FaweParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an input into a list of {@link java.util.Map.Entry} of {@link ParseEntry} and a list of the given arguments, where
|
||||
* arguments are given in square brackets, e.g. {@code #offset[2][10][2]}. Different entries may be separated by , or &
|
||||
* (OR and AND respectively)
|
||||
*
|
||||
* @param toParse the string to parse
|
||||
* @return a list of parsed entries and their arguments
|
||||
* @throws InputParseException if the input is not complete (has dangling characters)
|
||||
*/
|
||||
public static List<Map.Entry<ParseEntry, List<String>>> parse(String toParse) throws InputParseException {
|
||||
List<Map.Entry<ParseEntry, List<String>>> keys = new ArrayList<>();
|
||||
List<String> inputs = new ArrayList<>();
|
||||
List<Boolean> and = new ArrayList<>();
|
||||
int last = 0;
|
||||
outer:
|
||||
for (int i = 0; i < toParse.length(); i++) {
|
||||
char c = toParse.charAt(i);
|
||||
switch (c) {
|
||||
case ',':
|
||||
case '&':
|
||||
String result = toParse.substring(last, i);
|
||||
if (!result.isEmpty()) {
|
||||
inputs.add(result);
|
||||
and.add(c == '&');
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.parse.invalid-dangling-character", c));
|
||||
}
|
||||
last = i + 1;
|
||||
continue outer;
|
||||
default:
|
||||
if (c == '[') {
|
||||
int next = StringMan.findMatchingBracket(toParse, i);
|
||||
if (next != -1) {
|
||||
i = next;
|
||||
} else {
|
||||
toParse += "]";
|
||||
i = toParse.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
inputs.add(toParse.substring(last));
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
String full = inputs.get(i);
|
||||
String command = full;
|
||||
List<String> args = new ArrayList<>();
|
||||
while (!command.isEmpty() && command.charAt(command.length() - 1) == ']') {
|
||||
int startPos = StringMan.findMatchingBracket(command, command.length() - 1);
|
||||
if (startPos == -1) {
|
||||
break;
|
||||
}
|
||||
String arg = command.substring(startPos + 1, command.length() - 1);
|
||||
args.add(arg);
|
||||
command = full.substring(0, startPos);
|
||||
}
|
||||
Collections.reverse(args);
|
||||
ParseEntry entry = new ParseEntry(full, command, i > 0 ? and.get(i - 1) : false);
|
||||
keys.add(new AbstractMap.SimpleEntry<>(entry, args));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
protected PlatformCommandManager getPlatform() {
|
||||
return PlatformCommandManager.getInstance();
|
||||
}
|
||||
|
||||
public static class ParseEntry {
|
||||
|
||||
private final boolean and;
|
||||
private final String input;
|
||||
private final String full;
|
||||
|
||||
public ParseEntry(String full, String input, boolean type) {
|
||||
this.full = full;
|
||||
this.input = input;
|
||||
this.and = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives if the parsed entry was appended to the original input as an AND.
|
||||
*
|
||||
* @return if appended to input with '&' rather than ','
|
||||
*/
|
||||
public boolean isAnd() {
|
||||
return and;
|
||||
}
|
||||
|
||||
/**
|
||||
* The input "name" e.g. for {@code #offset[2][10][2]}, returns "offset"
|
||||
*
|
||||
* @return input name
|
||||
*/
|
||||
public String getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original full input, including arguments e.g. for {@code #offset[2][10][2]}, returns "#offset[2][10][2]"
|
||||
*
|
||||
* @return original full input
|
||||
*/
|
||||
public String getFull() {
|
||||
return full;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return input + " | " + and;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,7 @@ import java.util.stream.Stream;
|
||||
*
|
||||
* @param <E> the parse result.
|
||||
*/
|
||||
public abstract class RichParser<E> extends InputParser<E> {
|
||||
public abstract class RichParser<E> extends InputParser<E> implements AliasedParser {
|
||||
|
||||
private final String[] prefixes;
|
||||
|
||||
@ -51,7 +51,7 @@ public abstract class RichParser<E> extends InputParser<E> {
|
||||
@Nonnull
|
||||
private Function<String, Stream<? extends String>> extractArguments(String input) {
|
||||
return prefix -> {
|
||||
if (input.length() > prefix.length()) {
|
||||
if (input.length() > prefix.length() && prefix.startsWith(input + "[")) {
|
||||
// input already contains argument(s) -> extract them
|
||||
String[] strings = extractArguments(input.substring(prefix.length()), false);
|
||||
// rebuild the argument string without the last argument
|
||||
@ -69,10 +69,24 @@ public abstract class RichParser<E> extends InputParser<E> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the default prefix/name of the pattern/mask/transform.
|
||||
*
|
||||
* @return default prefix
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return this.prefixes[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all prefix/name aliases of the pattern/mask/transform
|
||||
*
|
||||
* @return all prefix/name aliases
|
||||
*/
|
||||
public List<String> getMatchedAliases() {
|
||||
return Arrays.asList(prefixes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return Arrays.stream(this.prefixes)
|
||||
@ -140,8 +154,15 @@ public abstract class RichParser<E> extends InputParser<E> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!requireClosing && open > 0) {
|
||||
arguments.add(input.substring(openIndex + 1));
|
||||
if (!requireClosing) {
|
||||
if (open > 0) {
|
||||
arguments.add(input.substring(openIndex + 1));
|
||||
} else {
|
||||
int last = input.lastIndexOf(']');
|
||||
if (last != -1) {
|
||||
arguments.add(input.substring(last));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requireClosing && open != 0) {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-bracketing", TextComponent.of("'[' or ']'?")));
|
||||
|
@ -1,189 +0,0 @@
|
||||
// TODO: Ping @MattBDev to reimplement 2020-02-04
|
||||
//*
|
||||
//package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
//
|
||||
//import com.boydti.fawe.command.FaweParser;
|
||||
//import com.boydti.fawe.command.SuggestInputParseException;
|
||||
//import com.boydti.fawe.config.Caption;
|
||||
//import com.boydti.fawe.util.StringMan;
|
||||
//import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
//import com.sk89q.worldedit.WorldEdit;
|
||||
//import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
//import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
//import com.sk89q.worldedit.extension.platform.Actor;
|
||||
//import com.sk89q.worldedit.extent.Extent;
|
||||
//import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
|
||||
//import com.sk89q.worldedit.function.mask.Mask;
|
||||
//import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
//import com.sk89q.worldedit.function.mask.MaskUnion;
|
||||
//import com.sk89q.worldedit.session.request.Request;
|
||||
//import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
//import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
//import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//import java.util.stream.Stream;
|
||||
//
|
||||
//public class DefaultMaskParser extends FaweParser<Mask> {
|
||||
// public DefaultMaskParser(WorldEdit worldEdit) {
|
||||
// super(worldEdit, "masks");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
// if (input.isEmpty()) {
|
||||
// throw new SuggestInputParseException("No input provided", "", () -> Stream.concat(Stream.of("#", ",", "&"), BlockTypes.getNameSpaces().stream().map(n -> n + ":")).collect(Collectors.toList()));
|
||||
// }
|
||||
// Extent extent = Request.request().getExtent();
|
||||
// if (extent == null) extent = context.getExtent();
|
||||
// List<List<Mask>> masks = new ArrayList<>();
|
||||
// masks.add(new ArrayList<>());
|
||||
//
|
||||
// final CommandLocals locals = new CommandLocals();
|
||||
// Actor actor = context != null ? context.getActor() : null;
|
||||
// if (actor != null) {
|
||||
// locals.put(Actor.class, actor);
|
||||
// }
|
||||
// try {
|
||||
// List<Map.Entry<ParseEntry, List<String>>> parsed = parse(input);
|
||||
// for (Map.Entry<ParseEntry, List<String>> entry : parsed) {
|
||||
// ParseEntry pe = entry.getKey();
|
||||
// final String command = pe.input;
|
||||
// String full = pe.full;
|
||||
// Mask mask = null;
|
||||
// if (command.isEmpty()) {
|
||||
// mask = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
// } else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// mask = parse(command + cmdArgs, context);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw SuggestInputParseException.of(e, full, () -> {
|
||||
//// try {
|
||||
//// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
//// if (suggestions.size() <= 2) {
|
||||
//// for (int i = 0; i < suggestions.size(); i++) {
|
||||
//// String suggestion = suggestions.get(i);
|
||||
//// if (suggestion.indexOf(' ') != 0) {
|
||||
//// String[] split = suggestion.split(" ");
|
||||
//// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
//// suggestions.set(i, suggestion);
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// return suggestions;
|
||||
//// } catch (CommandException e1) {
|
||||
//// throw new InputParseException(e1.getMessage());
|
||||
//// } catch (Throwable e2) {
|
||||
//// e2.printStackTrace();
|
||||
//// throw new InputParseException(e2.getMessage());
|
||||
//// }
|
||||
//// });
|
||||
// }
|
||||
// if (mask == null) {
|
||||
// // Legacy patterns
|
||||
// char char0 = command.charAt(0);
|
||||
// boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
// if (charMask && input.charAt(0) == '=') {
|
||||
// return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
// }
|
||||
// if (char0 == '#' || char0 == '?') {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw new SuggestInputParseException(new NoMatchException("Unknown mask: " + full + ", See: //masks"), full,
|
||||
//// () -> {
|
||||
//// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
//// return dispatcher.getAliases().stream().filter(
|
||||
//// s -> s.startsWith(command.toLowerCase(Locale.ROOT))
|
||||
//// ).collect(Collectors.toList());
|
||||
//// }
|
||||
//// );
|
||||
// }
|
||||
// // Legacy syntax
|
||||
// if (charMask) {
|
||||
// switch (char0) {
|
||||
// case '\\': //
|
||||
// case '/': //
|
||||
// case '{': //
|
||||
// case '$': //
|
||||
// case '%': {
|
||||
// String value = command.substring(1) + ((entry.getValue().isEmpty()) ? "" : "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
// if (value.contains(":")) {
|
||||
// if (value.charAt(0) == ':') value.replaceFirst(":", "");
|
||||
// value = value.replaceAll(":", "][");
|
||||
// }
|
||||
// mask = parseFromInput("#" + char0 + "[" + value + "]", context);
|
||||
// break;
|
||||
// }
|
||||
// case '|':
|
||||
// case '~':
|
||||
// case '<':
|
||||
// case '>':
|
||||
// case '!':
|
||||
// input = input.substring(input.indexOf(char0) + 1);
|
||||
// mask = parseFromInput(char0 + "[" + input + "]", context);
|
||||
// if (actor != null) {
|
||||
// actor.print(Caption.of("fawe.worldedit.help.command.clarifying.bracket", char0 + "[" + input + "]"));
|
||||
// }
|
||||
// return mask;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (mask == null) {
|
||||
// if (command.startsWith("[")) {
|
||||
// int end = command.lastIndexOf(']');
|
||||
// mask = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
// } else {
|
||||
// List<String> entries = entry.getValue();
|
||||
// BlockMaskBuilder builder = new BlockMaskBuilder();
|
||||
//// if (StringMan.containsAny(full, "\\^$.|?+(){}<>~$!%^&*+-/"))
|
||||
// {
|
||||
// try {
|
||||
// builder.addRegex(full);
|
||||
// } catch (InputParseException ignored) {}
|
||||
// }
|
||||
// if (mask == null) {
|
||||
// context.setPreferringWildcard(false);
|
||||
// context.setRestricted(false);
|
||||
// BaseBlock block = worldEdit.getBlockFactory().parseFromInput(full, context);
|
||||
// builder.add(block);
|
||||
// mask = builder.build(extent);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (pe.and) {
|
||||
// masks.add(new ArrayList<>());
|
||||
// }
|
||||
// masks.get(masks.size() - 1).add(mask);
|
||||
// }
|
||||
// } catch (InputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// throw new InputParseException(e.getMessage(), e);
|
||||
// }
|
||||
// List<Mask> maskUnions = new ArrayList<>();
|
||||
// for (List<Mask> maskList : masks) {
|
||||
// if (maskList.size() == 1) {
|
||||
// maskUnions.add(maskList.get(0));
|
||||
// } else if (maskList.size() != 0) {
|
||||
// maskUnions.add(new MaskUnion(maskList));
|
||||
// }
|
||||
// }
|
||||
// if (maskUnions.size() == 1) {
|
||||
// return maskUnions.get(0);
|
||||
// } else if (maskUnions.size() != 0) {
|
||||
// return new MaskIntersection(maskUnions);
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
@ -0,0 +1,241 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.command.SuggestInputParseException;
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.FaweParser;
|
||||
import com.fastasyncworldedit.core.function.mask.BlockMaskBuilder;
|
||||
import com.fastasyncworldedit.core.function.mask.MaskUnion;
|
||||
import com.fastasyncworldedit.core.util.StringMan;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.internal.command.CommandArgParser;
|
||||
import com.sk89q.worldedit.internal.util.Substring;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import org.enginehub.piston.inject.MemoizingValueAccess;
|
||||
import org.enginehub.piston.suggestion.Suggestion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Attempts to parse masks given rich inputs, allowing for & and ,. Also allows for nested masks
|
||||
*/
|
||||
public class RichMaskParser extends FaweParser<Mask> {
|
||||
|
||||
/**
|
||||
* New instance
|
||||
*
|
||||
* @param worldEdit {@link WorldEdit} instance.
|
||||
*/
|
||||
public RichMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (input.isEmpty()) {
|
||||
throw new SuggestInputParseException("No input provided", "", () -> Stream
|
||||
.of("#", ",", "&")
|
||||
.map(n -> n + ":")
|
||||
.collect(Collectors.toList())
|
||||
// TODO namespaces
|
||||
);
|
||||
}
|
||||
Extent extent = context.getExtent();
|
||||
if (extent == null) {
|
||||
extent = Request.request().getExtent();
|
||||
}
|
||||
List<List<Mask>> masks = new ArrayList<>();
|
||||
masks.add(new ArrayList<>());
|
||||
|
||||
final CommandLocals locals = new CommandLocals();
|
||||
Actor actor = context.getActor();
|
||||
if (actor != null) {
|
||||
locals.put(Actor.class, actor);
|
||||
}
|
||||
try {
|
||||
List<Map.Entry<ParseEntry, List<String>>> parsed = parse(input);
|
||||
for (Map.Entry<ParseEntry, List<String>> entry : parsed) {
|
||||
ParseEntry pe = entry.getKey();
|
||||
final String command = pe.getInput();
|
||||
String full = pe.getFull();
|
||||
Mask mask = null;
|
||||
if (command.isEmpty()) {
|
||||
mask = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
} else if (!worldEdit.getMaskFactory().containsAlias(command)) {
|
||||
// Legacy patterns
|
||||
char char0 = command.charAt(0);
|
||||
boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
if (charMask && input.charAt(0) == '=') {
|
||||
return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
}
|
||||
if (char0 == '#') {
|
||||
throw new SuggestInputParseException(
|
||||
new NoMatchException(Caption.of("fawe.error.parse.unknown-mask", full,
|
||||
TextComponent
|
||||
.of("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
)
|
||||
.clickEvent(ClickEvent.openUrl(
|
||||
"https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
))
|
||||
)),
|
||||
full,
|
||||
() -> {
|
||||
if (full.length() == 1) {
|
||||
return new ArrayList<>(worldEdit.getMaskFactory().getSuggestions(""));
|
||||
}
|
||||
return new ArrayList<>(worldEdit
|
||||
.getMaskFactory()
|
||||
.getSuggestions(command.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
);
|
||||
}
|
||||
// Legacy syntax
|
||||
if (charMask) {
|
||||
switch (char0) {
|
||||
case '\\': //
|
||||
case '/': //
|
||||
case '{': //
|
||||
case '$': //
|
||||
case '%': {
|
||||
String value = command.substring(1) + ((entry.getValue().isEmpty())
|
||||
? ""
|
||||
: "[" + StringMan.join(
|
||||
entry.getValue(),
|
||||
"]["
|
||||
) + "]");
|
||||
if (value.contains(":")) {
|
||||
if (value.charAt(0) == ':') {
|
||||
value = value.replaceFirst(":", "");
|
||||
}
|
||||
value = value.replaceAll(":", "][");
|
||||
}
|
||||
mask = parseFromInput("#" + char0 + "[" + value + "]", context);
|
||||
break;
|
||||
}
|
||||
case '|':
|
||||
case '~':
|
||||
case '<':
|
||||
case '>':
|
||||
case '!':
|
||||
input = input.substring(input.indexOf(char0) + 1);
|
||||
mask = parseFromInput(char0 + "[" + input + "]", context);
|
||||
if (actor != null) {
|
||||
actor.print(Caption.of(
|
||||
"fawe.worldedit.help.command.clarifying.bracket",
|
||||
char0 + "[" + input +
|
||||
"]"
|
||||
));
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
if (mask == null) {
|
||||
if (command.startsWith("[")) {
|
||||
int end = command.lastIndexOf(']');
|
||||
mask = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
} else {
|
||||
BlockMaskBuilder builder = new BlockMaskBuilder();
|
||||
try {
|
||||
builder.addRegex(full);
|
||||
} catch (InputParseException ignored) {
|
||||
}
|
||||
context.setPreferringWildcard(false);
|
||||
context.setRestricted(false);
|
||||
BaseBlock block = worldEdit.getBlockFactory().parseFromInput(full, context);
|
||||
builder.add(block);
|
||||
mask = builder.build(extent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<String> args = entry.getValue();
|
||||
try {
|
||||
mask = worldEdit.getMaskFactory().parseWithoutRich(full, context);
|
||||
} catch (SuggestInputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
throw SuggestInputParseException.of(e, full, () -> {
|
||||
try {
|
||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
List<Substring> split =
|
||||
CommandArgParser.forArgString(cmdArgs).parseArgs().collect(Collectors.toList());
|
||||
List<String> argStrings = split
|
||||
.stream()
|
||||
.map(Substring::getSubstring)
|
||||
.collect(Collectors.toList());
|
||||
MemoizingValueAccess access = getPlatform().initializeInjectedValues(() -> cmdArgs,
|
||||
actor,
|
||||
null, true
|
||||
);
|
||||
List<String> suggestions = getPlatform().getCommandManager().getSuggestions(
|
||||
access,
|
||||
argStrings
|
||||
).stream().map(Suggestion::getSuggestion).collect(Collectors.toUnmodifiableList());
|
||||
List<String> result = new ArrayList<>();
|
||||
if (suggestions.size() <= 2) {
|
||||
for (int i = 0; i < suggestions.size(); i++) {
|
||||
String suggestion = suggestions.get(i);
|
||||
if (suggestion.indexOf(' ') != 0) {
|
||||
String[] splitSuggestion = suggestion.split(" ");
|
||||
suggestion = "[" + StringMan.join(splitSuggestion, "][") + "]";
|
||||
result.set(i, suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
throw new InputParseException(Caption.of(e2.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (pe.isAnd()) {
|
||||
masks.add(new ArrayList<>());
|
||||
}
|
||||
masks.get(masks.size() - 1).add(mask);
|
||||
}
|
||||
} catch (InputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new InputParseException(Caption.of(e.getMessage()), e);
|
||||
}
|
||||
List<Mask> maskUnions = new ArrayList<>();
|
||||
for (List<Mask> maskList : masks) {
|
||||
if (maskList.size() == 1) {
|
||||
maskUnions.add(maskList.get(0));
|
||||
} else if (maskList.size() != 0) {
|
||||
maskUnions.add(new MaskUnion(maskList));
|
||||
}
|
||||
}
|
||||
if (maskUnions.size() == 1) {
|
||||
return maskUnions.get(0);
|
||||
} else if (maskUnions.size() != 0) {
|
||||
return new MaskIntersection(maskUnions);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.AngleColorPattern;
|
||||
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.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AngleColorPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public AngleColorPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#anglecolor", "#anglecolour");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index != 0) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[distance] (e.g. " + getPrefix() + "[10])")
|
||||
));
|
||||
}
|
||||
int distance = Integer.parseInt(input[0]);
|
||||
return new AngleColorPattern(context.requireExtent(), context.requireSession(), distance);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.AverageColorPattern;
|
||||
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.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AverageColorPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public AverageColorPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#averagecolor", "#averagecolour");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index > 4) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 4) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[r][g][b][a] (e.g. " + getPrefix() + "[156][100][0][120])")
|
||||
));
|
||||
}
|
||||
return new AverageColorPattern(
|
||||
context.requireExtent(),
|
||||
context.requireSession(),
|
||||
Integer.parseInt(input[0]),
|
||||
Integer.parseInt(input[1]),
|
||||
Integer.parseInt(input[2]),
|
||||
Integer.parseInt(input[3])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ public class BiomePatternParser extends RichParser<Pattern> {
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public BiomePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#biome");
|
||||
super(worldEdit, "#biome", "$");
|
||||
}
|
||||
|
||||
// overridden to provide $<biome> too
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.BufferedPattern2D;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BufferedPattern2DParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public BufferedPattern2DParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#buffer2d");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(input[0], context);
|
||||
return new BufferedPattern2D(context.requireActor(), inner);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.util.MathMan;
|
||||
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.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.awt.Color;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ColorPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public ColorPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#color", "#colour");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index > 4) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 4) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[r][g][b][a] (e.g. " + getPrefix() + "[156][100][0][120])")
|
||||
));
|
||||
}
|
||||
Color color = new Color(
|
||||
MathMan.clamp(Integer.parseInt(input[0]), 0, 255),
|
||||
MathMan.clamp(Integer.parseInt(input[1]), 0, 255),
|
||||
MathMan.clamp(Integer.parseInt(input[2]), 0, 255),
|
||||
MathMan.clamp(Integer.parseInt(input[3]), 0, 255)
|
||||
);
|
||||
return context.requireSession().getTextureUtil().getNearestBlock(color.getRGB());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.function.pattern.ShadePattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DarkenPatternParser extends SimpleInputParser<Pattern> {
|
||||
|
||||
private final List<String> aliases = Collections.singletonList("#darken");
|
||||
|
||||
/**
|
||||
* Create a new simple parser with a defined prefix for the result.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public DarkenPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new ShadePattern(context.requireExtent(), context.requireSession(), true);
|
||||
}
|
||||
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
// TODO: Ping @MattBDev to reimplement (or remove because this class is stupid) 2020-02-04
|
||||
///*
|
||||
//package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
//
|
||||
//import com.boydti.fawe.command.FaweParser;
|
||||
//import com.boydti.fawe.command.SuggestInputParseException;
|
||||
//import com.boydti.fawe.object.random.TrueRandom;
|
||||
//import com.boydti.fawe.util.StringMan;
|
||||
//import com.google.common.collect.Iterables;
|
||||
//import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
//import com.sk89q.worldedit.WorldEdit;
|
||||
//import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
//import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
//import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
//import com.sk89q.worldedit.extension.platform.Actor;
|
||||
//import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||
//import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
//import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
//import com.sk89q.worldedit.internal.expression.Expression;
|
||||
//import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//import java.util.stream.Stream;
|
||||
//
|
||||
//public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||
//
|
||||
// public DefaultPatternParser(WorldEdit worldEdit) {
|
||||
// super(worldEdit, "patterns");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
// if (input.isEmpty()) {
|
||||
// throw new SuggestInputParseException("No input provided", "", () -> Stream.concat(Stream.of("#", ",", "&"), BlockTypes.getNameSpaces().stream().map(n -> n + ":")).collect(Collectors.toList()));
|
||||
// }
|
||||
// List<Double> chances = new ArrayList<>();
|
||||
// List<Pattern> patterns = new ArrayList<>();
|
||||
// final CommandLocals locals = new CommandLocals();
|
||||
// Actor actor = context != null ? context.getActor() : null;
|
||||
// if (actor != null) {
|
||||
// locals.put(Actor.class, actor);
|
||||
// }
|
||||
// try {
|
||||
// for (Map.Entry<ParseEntry, List<String>> entry : parse(input)) {
|
||||
// ParseEntry pe = entry.getKey();
|
||||
// final String command = pe.input;
|
||||
// String full = pe.full;
|
||||
// Pattern pattern = null;
|
||||
// double chance = 1;
|
||||
// if (command.isEmpty()) {
|
||||
// pattern = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
// } else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// pattern = parse(command + cmdArgs, context);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw SuggestInputParseException.of(e, full, () -> {
|
||||
//// try {
|
||||
//// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
//// if (suggestions.size() <= 2) {
|
||||
//// for (int i = 0; i < suggestions.size(); i++) {
|
||||
//// String suggestion = suggestions.get(i);
|
||||
//// if (suggestion.indexOf(' ') != 0) {
|
||||
//// String[] split = suggestion.split(" ");
|
||||
//// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
//// suggestions.set(i, suggestion);
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// return suggestions;
|
||||
//// } catch (CommandException e1) {
|
||||
//// throw new InputParseException(e1.getMessage());
|
||||
//// } catch (Throwable e2) {
|
||||
//// e2.printStackTrace();
|
||||
//// throw new InputParseException(e2.getMessage());
|
||||
//// }
|
||||
//// });
|
||||
// }
|
||||
// if (pattern == null) {
|
||||
// // Legacy patterns
|
||||
// char char0 = command.charAt(0);
|
||||
// boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
// if (charMask && input.charAt(0) == '=') {
|
||||
// return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
// }
|
||||
// if (char0 == '#') {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw new SuggestInputParseException(new NoMatchException("Unknown pattern: " + full + ", See: //patterns"), full,
|
||||
//// () -> {
|
||||
//// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
//// return dispatcher.getAliases().stream().filter(
|
||||
//// s -> s.startsWith(command.toLowerCase(Locale.ROOT))
|
||||
//// ).collect(Collectors.toList());
|
||||
//// }
|
||||
//// );
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (charMask) {
|
||||
// if (char0 == '$') {
|
||||
// String value = command.substring(1) + ((entry.getValue().isEmpty()) ? ""
|
||||
// : "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
// if (value.contains(":")) {
|
||||
// if (value.charAt(0) == ':') {
|
||||
// value.replaceFirst(":", "");
|
||||
// }
|
||||
// value = value.replaceAll(":", "][");
|
||||
// }
|
||||
// pattern = parseFromInput(char0 + "[" + value + "]", context);
|
||||
// }
|
||||
// }
|
||||
// if (pattern == null) {
|
||||
// if (command.startsWith("[")) {
|
||||
// int end = command.lastIndexOf(']');
|
||||
// pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
// } else {
|
||||
// int percentIndex = command.indexOf('%');
|
||||
// if (percentIndex != -1) { // Legacy percent pattern
|
||||
// chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
// String value = command.substring(percentIndex + 1);
|
||||
// if (!entry.getValue().isEmpty()) {
|
||||
// if (!value.isEmpty()) value += " ";
|
||||
// value += StringMan.join(entry.getValue(), " ");
|
||||
// }
|
||||
// pattern = parseFromInput(value, context);
|
||||
// } else { // legacy block pattern
|
||||
// try {
|
||||
// pattern = worldEdit.getBlockFactory().parseFromInput(pe.full, context);
|
||||
// } catch (NoMatchException e) {
|
||||
// throw new NoMatchException(e.getMessage() + " See: //patterns");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (pattern != null) {
|
||||
// patterns.add(pattern);
|
||||
// chances.add(chance);
|
||||
// }
|
||||
// }
|
||||
// } catch (InputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// throw new InputParseException(e.getMessage(), e);
|
||||
// }
|
||||
// if (patterns.isEmpty()) {
|
||||
// return null;
|
||||
// }
|
||||
// if (patterns.size() == 1) {
|
||||
// return patterns.get(0);
|
||||
// }
|
||||
// RandomPattern random = new RandomPattern(new TrueRandom());
|
||||
// for (int i = 0; i < patterns.size(); i++) {
|
||||
// random.add(patterns.get(i), chances.get(i));
|
||||
// }
|
||||
// return random;
|
||||
// }
|
||||
//}
|
@ -0,0 +1,46 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.DesaturatePattern;
|
||||
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.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DesaturatePatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public DesaturatePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#desaturate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[percent] (e.g. " + getPrefix() + "[90])")
|
||||
));
|
||||
}
|
||||
return new DesaturatePattern(context.requireExtent(), context.requireSession(), Double.parseDouble(arguments[0]) / 100);
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,11 @@ public class ExistingPatternParser extends SimpleInputParser<Pattern> {
|
||||
|
||||
private final List<String> aliases = Collections.singletonList("#existing");
|
||||
|
||||
/**
|
||||
* Create a new simple parser with a defined prefix for the result.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public ExistingPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.pattern.ExpressionPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ExpressionPatternParser extends SimpleInputParser<Pattern> {
|
||||
|
||||
private final List<String> aliases = Collections.singletonList("=");
|
||||
|
||||
/**
|
||||
* Create a new simple parser with a defined prefix for the result.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public ExpressionPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
try {
|
||||
Expression exp = Expression.compile(input.substring(1), "x", "y", "z");
|
||||
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
|
||||
context.requireExtent(), Vector3.ONE, Vector3.ZERO);
|
||||
exp.setEnvironment(env);
|
||||
return new ExpressionPattern(exp);
|
||||
} catch (ExpressionException e) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"worldedit.error.parser.invalid-expression",
|
||||
TextComponent.of(e.getMessage())
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.function.pattern.ShadePattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LightenPatternParser extends SimpleInputParser<Pattern> {
|
||||
|
||||
private final List<String> aliases = Collections.singletonList("#lighten");
|
||||
|
||||
/**
|
||||
* Create a new simple parser with a defined prefix for the result.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public LightenPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new ShadePattern(context.requireExtent(), context.requireSession(), false);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.LinearBlockPattern;
|
||||
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.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LinearPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public LinearPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear", "#l");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (inner instanceof BlockStateHolder) {
|
||||
return inner;
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new LinearBlockPattern(patterns.toArray(new Pattern[0]));
|
||||
}
|
||||
throw new InputParseException(Caption.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.MaskedPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MaskedPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public MaskedPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#mask");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 3) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[mask][pattern][pattern] (e.g. " + getPrefix() + "[oak_planks][dirt][stone])")
|
||||
));
|
||||
}
|
||||
Mask mask = this.worldEdit.getMaskFactory().parseFromInput(arguments[0], context);
|
||||
Pattern inner1 = this.worldEdit.getPatternFactory().parseFromInput(arguments[1], context);
|
||||
Pattern inner2 = this.worldEdit.getPatternFactory().parseFromInput(arguments[2], context);
|
||||
return new MaskedPattern(mask, inner1, inner2);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.NoXPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class NoXPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public NoXPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#!x", "#nx", "#nox");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(input[0], context);
|
||||
return new NoXPattern(inner);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.NoYPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class NoYPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public NoYPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#!y", "#ny", "#noy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(input[0], context);
|
||||
return new NoYPattern(inner);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.NoZPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class NoZPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public NoZPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#!z", "#nz", "#noz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(input[0], context);
|
||||
return new NoZPattern(inner);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.OffsetPattern;
|
||||
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;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class OffsetPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public OffsetPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#offset");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 2 && arguments.length != 4) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone][2][0][4])")
|
||||
));
|
||||
}
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (arguments.length == 4) {
|
||||
x = Integer.parseInt(arguments[1]);
|
||||
y = Integer.parseInt(arguments[2]);
|
||||
z = Integer.parseInt(arguments[3]);
|
||||
} else {
|
||||
x = y = z = Integer.parseInt(arguments[1]);
|
||||
}
|
||||
Extent extent = context.requireExtent();
|
||||
int minY = extent.getMinY();
|
||||
int maxY = extent.getMaxY();
|
||||
return new OffsetPattern(inner, x, y, z, minY, maxY);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
|
||||
import com.fastasyncworldedit.core.function.pattern.RandomFullClipboardPattern;
|
||||
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.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomFullClipboardPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RandomFullClipboardPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#fullcopy");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 1:
|
||||
case 2:
|
||||
return SuggestionHelper.suggestBoolean(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length == 0 || arguments.length > 3) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[#copy][true][false])")
|
||||
));
|
||||
}
|
||||
try {
|
||||
boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]);
|
||||
boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]);
|
||||
List<ClipboardHolder> clipboards;
|
||||
switch (arguments[0].toLowerCase()) {
|
||||
case "#copy":
|
||||
case "#clipboard":
|
||||
ClipboardHolder clipboard = context.requireSession().getExistingClipboard();
|
||||
if (clipboard == null) {
|
||||
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix()));
|
||||
}
|
||||
clipboards = Collections.singletonList(clipboard);
|
||||
break;
|
||||
default:
|
||||
Actor player = context.requireActor();
|
||||
MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player,
|
||||
arguments[0], ClipboardFormats.findByAlias("fast"), true
|
||||
);
|
||||
if (multi == null) {
|
||||
multi = ClipboardFormats.loadAllFromInput(player,
|
||||
arguments[0], ClipboardFormats.findByAlias("sponge"), true
|
||||
);
|
||||
}
|
||||
if (multi == null) {
|
||||
multi = ClipboardFormats.loadAllFromInput(player,
|
||||
arguments[0], ClipboardFormats.findByAlias("mcedit"), true
|
||||
);
|
||||
}
|
||||
if (multi == null) {
|
||||
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0]));
|
||||
}
|
||||
clipboards = multi.getHolders();
|
||||
break;
|
||||
}
|
||||
return new RandomFullClipboardPattern(clipboards, rotate, flip);
|
||||
} catch (IOException e) {
|
||||
throw new InputParseException(Caption.of(e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.RandomOffsetPattern;
|
||||
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;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomOffsetPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RandomOffsetPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#spread", "#randomoffset");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 2 && arguments.length != 4) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone][2][0][4])")
|
||||
));
|
||||
}
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (arguments.length == 4) {
|
||||
x = Integer.parseInt(arguments[1]);
|
||||
y = Integer.parseInt(arguments[2]);
|
||||
z = Integer.parseInt(arguments[3]);
|
||||
} else {
|
||||
x = y = z = Integer.parseInt(arguments[1]);
|
||||
}
|
||||
Extent extent = context.requireExtent();
|
||||
return new RandomOffsetPattern(inner, x, y, z, extent.getMinY(), extent.getMaxY());
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,11 @@ import java.util.stream.Stream;
|
||||
|
||||
public class RandomPatternParser extends InputParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new input parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RandomPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.RelativePattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RelativePatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RelativePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#relative", "#~", "#r", "#rel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 1) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(input[0], context);
|
||||
Extent extent = context.requireExtent();
|
||||
return new RelativePattern(inner, extent.getMinY(), extent.getMaxY());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.command.SuggestInputParseException;
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.FaweParser;
|
||||
import com.fastasyncworldedit.core.math.random.TrueRandom;
|
||||
import com.fastasyncworldedit.core.util.StringMan;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.command.CommandArgParser;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.util.Substring;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import org.enginehub.piston.inject.MemoizingValueAccess;
|
||||
import org.enginehub.piston.suggestion.Suggestion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RichPatternParser extends FaweParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich pattern-parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RichPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (input.isEmpty()) {
|
||||
throw new SuggestInputParseException(
|
||||
"No input provided",
|
||||
"",
|
||||
() -> Stream
|
||||
.concat(Stream.of("#", ",", "&"), BlockTypes.getNameSpaces().stream().map(n -> n + ":"))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
List<Double> chances = new ArrayList<>();
|
||||
List<Pattern> patterns = new ArrayList<>();
|
||||
final CommandLocals locals = new CommandLocals();
|
||||
Actor actor = context != null ? context.getActor() : null;
|
||||
if (actor != null) {
|
||||
locals.put(Actor.class, actor);
|
||||
}
|
||||
try {
|
||||
for (Map.Entry<ParseEntry, List<String>> entry : parse(input)) {
|
||||
ParseEntry pe = entry.getKey();
|
||||
final String command = pe.getInput();
|
||||
String full = pe.getFull();
|
||||
Pattern pattern = null;
|
||||
double chance = 1;
|
||||
if (command.isEmpty()) {
|
||||
pattern = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
} else if (!worldEdit.getPatternFactory().containsAlias(command)) {
|
||||
// Legacy patterns
|
||||
char char0 = command.charAt(0);
|
||||
boolean charPattern = input.length() > 1 && input.charAt(1) != '[';
|
||||
if (charPattern && input.charAt(0) == '=') {
|
||||
return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
}
|
||||
if (char0 == '#' && command.length() > 1 && command.charAt(1) != '#') {
|
||||
throw new SuggestInputParseException(
|
||||
new NoMatchException(Caption.of("fawe.error.parse.unknown-pattern", full,
|
||||
TextComponent
|
||||
.of("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
)
|
||||
.clickEvent(
|
||||
ClickEvent.openUrl(
|
||||
"https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
))
|
||||
)),
|
||||
full,
|
||||
() -> {
|
||||
if (full.length() == 1) {
|
||||
return new ArrayList<>(worldEdit.getPatternFactory().getSuggestions(""));
|
||||
}
|
||||
return new ArrayList<>(worldEdit
|
||||
.getPatternFactory()
|
||||
.getSuggestions(command.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (charPattern) {
|
||||
if (char0 == '$' || char0 == '^' || char0 == '*' || (char0 == '#' && input.charAt(1) == '#')) {
|
||||
pattern = worldEdit.getPatternFactory().parseWithoutRich(full, context);
|
||||
}
|
||||
}
|
||||
if (pattern == null) {
|
||||
if (command.startsWith("[")) {
|
||||
int end = command.lastIndexOf(']');
|
||||
pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
} else {
|
||||
int percentIndex = command.indexOf('%');
|
||||
if (percentIndex != -1) { // Legacy percent pattern
|
||||
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
String value = command.substring(percentIndex + 1);
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
if (!value.isEmpty()) {
|
||||
value += " ";
|
||||
}
|
||||
value += StringMan.join(entry.getValue(), " ");
|
||||
}
|
||||
pattern = parseFromInput(value, context);
|
||||
} else { // legacy block pattern
|
||||
try {
|
||||
pattern = worldEdit.getBlockFactory().parseFromInput(pe.getFull(), context);
|
||||
} catch (NoMatchException e) {
|
||||
throw new NoMatchException(Caption.of("fawe.error.parse.unknown-pattern", full,
|
||||
TextComponent
|
||||
.of("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
)
|
||||
.clickEvent(
|
||||
com.sk89q.worldedit.util.formatting.text.event.ClickEvent.openUrl(
|
||||
"https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<String> args = entry.getValue();
|
||||
try {
|
||||
pattern = worldEdit.getPatternFactory().parseWithoutRich(full, context);
|
||||
} catch (SuggestInputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
throw SuggestInputParseException.of(e, full, () -> {
|
||||
try {
|
||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
List<Substring> split =
|
||||
CommandArgParser.forArgString(cmdArgs).parseArgs().collect(Collectors.toList());
|
||||
List<String> argStrings = split
|
||||
.stream()
|
||||
.map(Substring::getSubstring)
|
||||
.collect(Collectors.toList());
|
||||
MemoizingValueAccess access = getPlatform().initializeInjectedValues(() -> cmdArgs,
|
||||
actor,
|
||||
null, true
|
||||
);
|
||||
List<String> suggestions = getPlatform().getCommandManager().getSuggestions(
|
||||
access,
|
||||
argStrings
|
||||
).stream().map(Suggestion::getSuggestion).collect(Collectors.toUnmodifiableList());
|
||||
List<String> result = new ArrayList<>();
|
||||
if (suggestions.size() <= 2) {
|
||||
for (int i = 0; i < suggestions.size(); i++) {
|
||||
String suggestion = suggestions.get(i);
|
||||
if (suggestion.indexOf(' ') != 0) {
|
||||
String[] splitSuggestion = suggestion.split(" ");
|
||||
suggestion = "[" + StringMan.join(splitSuggestion, "][") + "]";
|
||||
result.set(i, suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
throw new InputParseException(Caption.of(e2.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (pattern != null) {
|
||||
patterns.add(pattern);
|
||||
chances.add(chance);
|
||||
}
|
||||
}
|
||||
} catch (InputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new InputParseException(Caption.of(e.getMessage()), e);
|
||||
}
|
||||
if (patterns.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (patterns.size() == 1) {
|
||||
return patterns.get(0);
|
||||
}
|
||||
RandomPattern random = new RandomPattern(new TrueRandom());
|
||||
for (int i = 0; i < patterns.size(); i++) {
|
||||
random.add(patterns.get(i), chances.get(i));
|
||||
}
|
||||
return random;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.SaturatePattern;
|
||||
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.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SaturatePatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public SaturatePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#saturate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index > 3) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(@Nonnull String[] input, ParserContext context) throws InputParseException {
|
||||
if (input.length != 4) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[r][g][b][a] (e.g. " + getPrefix() + "[156][100][0][120])")
|
||||
));
|
||||
}
|
||||
return new SaturatePattern(context.requireExtent(), context.requireSession(),
|
||||
Integer.parseInt(input[0]),
|
||||
Integer.parseInt(input[1]),
|
||||
Integer.parseInt(input[2]),
|
||||
Integer.parseInt(input[3])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,11 @@ public class SimplexPatternParser extends NoisePatternParser {
|
||||
|
||||
private static final String SIMPLEX_NAME = "simplex";
|
||||
|
||||
/**
|
||||
* Create a new rich pattern parser with a defined prefix for the result.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public SimplexPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, SIMPLEX_NAME, SimplexNoiseGenerator::new);
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.SolidRandomOffsetPattern;
|
||||
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;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SolidRandomOffsetPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public SolidRandomOffsetPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#solidspread");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 2 && arguments.length != 4) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone][2][0][4])")
|
||||
));
|
||||
}
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (arguments.length == 4) {
|
||||
x = Integer.parseInt(arguments[1]);
|
||||
y = Integer.parseInt(arguments[2]);
|
||||
z = Integer.parseInt(arguments[3]);
|
||||
} else {
|
||||
x = y = z = Integer.parseInt(arguments[1]);
|
||||
}
|
||||
Extent extent = context.requireExtent();
|
||||
return new SolidRandomOffsetPattern(inner, x, y, z, extent.getMinY(), extent.getMaxY());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.SurfaceRandomOffsetPattern;
|
||||
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;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SurfaceRandomOffsetPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public SurfaceRandomOffsetPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#surfacespread");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 2) {
|
||||
throw new InputParseException(Caption.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone][2])")
|
||||
));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
int distance = Integer.parseInt(arguments[1]);
|
||||
Extent extent = context.requireExtent();
|
||||
return new SurfaceRandomOffsetPattern(inner, distance, extent.getMinY(), extent.getMaxY());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.Linear3DTransform;
|
||||
import com.fastasyncworldedit.core.extent.transform.RandomTransform;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear3DTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public Linear3DTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear3d", "#l3d");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
return null;
|
||||
}
|
||||
ResettableExtent inner = worldEdit.getTransformFactory().parseFromInput(arguments[0], context);
|
||||
if (inner instanceof RandomTransform) {
|
||||
return new Linear3DTransform(((RandomTransform) inner).getExtents().toArray(new ResettableExtent[0]));
|
||||
}
|
||||
return inner; // TODO what about non-random transforms?
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.LinearTransform;
|
||||
import com.fastasyncworldedit.core.extent.transform.RandomTransform;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LinearTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public LinearTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear", "#l");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
return null;
|
||||
}
|
||||
ResettableExtent inner = worldEdit.getTransformFactory().parseFromInput(arguments[0], context);
|
||||
if (inner instanceof RandomTransform) {
|
||||
return new LinearTransform(((RandomTransform) inner).getExtents().toArray(new ResettableExtent[0]));
|
||||
}
|
||||
return inner; // TODO what about non-random transforms?
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.transform.OffsetTransform;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
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;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class OffsetTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public OffsetTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#offset");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
} else if (index == 3) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 3 && arguments.length != 4) {
|
||||
throw new InputParseException(TranslatableComponent.of(
|
||||
"fawe.error.command.syntax",
|
||||
TextComponent.of("#offset[x][y][z]")
|
||||
));
|
||||
}
|
||||
int xOffset = Integer.parseInt(arguments[0]);
|
||||
int yOffset = Integer.parseInt(arguments[1]);
|
||||
int zOffset = Integer.parseInt(arguments[2]);
|
||||
Extent extent;
|
||||
extent = arguments.length == 4 ? worldEdit.getTransformFactory().parseFromInput(arguments[3], context) :
|
||||
context.requireExtent();
|
||||
return new OffsetTransform(extent, xOffset, yOffset, zOffset);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.PatternTransform;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PatternTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public PatternTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#pattern");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
} else if (index == 1) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length > 2) {
|
||||
return null;
|
||||
}
|
||||
Pattern pattern = worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
Extent extent = arguments.length == 2 ? worldEdit.getTransformFactory().parseFromInput(arguments[1], context) :
|
||||
context.requireExtent();
|
||||
return new PatternTransform(extent, pattern);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.RandomTransform;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomTransformParser extends InputParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RandomTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.empty();
|
||||
}
|
||||
List<String> split = StringUtil.split(input, ',', '[', ']');
|
||||
if (split.size() == 1) {
|
||||
return Stream.empty();
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < split.size() - 1; i++) {
|
||||
builder.append(split.get(i)).append(',');
|
||||
}
|
||||
String previous = builder.toString();
|
||||
return worldEdit.getTransformFactory().getSuggestions(split.get(split.size() - 1)).stream()
|
||||
.map(s -> previous + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (input.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<String> split = StringUtil.split(input, ',', '[', ']');
|
||||
if (split.size() == 1) {
|
||||
return null;
|
||||
}
|
||||
RandomTransform randomTransform = new RandomTransform();
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
ResettableExtent transform = worldEdit.getTransformFactory().parseFromInput(split.get(i), context);
|
||||
randomTransform.add(transform, 1d);
|
||||
}
|
||||
return randomTransform;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.command.SuggestInputParseException;
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.FaweParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.MultiTransform;
|
||||
import com.fastasyncworldedit.core.extent.transform.RandomTransform;
|
||||
import com.fastasyncworldedit.core.math.random.TrueRandom;
|
||||
import com.fastasyncworldedit.core.util.StringMan;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Attempts to parse transforms given rich inputs, allowing for & and ,. Also allows for nested transforms
|
||||
*/
|
||||
public class RichTransformParser extends FaweParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* New instance
|
||||
*
|
||||
* @param worldEdit {@link WorldEdit} instance.
|
||||
*/
|
||||
public RichTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (input.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Double> unionChances = new ArrayList<>();
|
||||
List<Double> intersectionChances = new ArrayList<>();
|
||||
|
||||
List<ResettableExtent> intersection = new ArrayList<>();
|
||||
List<ResettableExtent> union = new ArrayList<>();
|
||||
final CommandLocals locals = new CommandLocals();
|
||||
Actor actor = context != null ? context.getActor() : null;
|
||||
if (actor != null) {
|
||||
locals.put(Actor.class, actor);
|
||||
}
|
||||
try {
|
||||
List<Map.Entry<ParseEntry, List<String>>> parsed = parse(input);
|
||||
for (Map.Entry<ParseEntry, List<String>> entry : parsed) {
|
||||
ParseEntry pe = entry.getKey();
|
||||
String command = pe.getInput();
|
||||
ResettableExtent transform;
|
||||
double chance = 1;
|
||||
if (command.isEmpty()) {
|
||||
transform = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
} else if (!worldEdit.getTransformFactory().containsAlias(command)) {
|
||||
// Legacy syntax
|
||||
int percentIndex = command.indexOf('%');
|
||||
if (percentIndex != -1) { // Legacy percent pattern
|
||||
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
command = command.substring(percentIndex + 1);
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
if (!command.isEmpty()) {
|
||||
command += " ";
|
||||
}
|
||||
command += StringMan.join(entry.getValue(), " ");
|
||||
}
|
||||
transform = parseFromInput(command, context);
|
||||
} else {
|
||||
throw new NoMatchException(Caption.of("fawe.error.parse.unknown-transform", pe.getFull(),
|
||||
TextComponent
|
||||
.of("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
)
|
||||
.clickEvent(ClickEvent.openUrl(
|
||||
"https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
))
|
||||
));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
transform = worldEdit.getTransformFactory().parseWithoutRich(pe.getFull(), context);
|
||||
} catch (SuggestInputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
throw new NoMatchException(Caption.of("fawe.error.parse.unknown-transform", pe.getFull(),
|
||||
TextComponent
|
||||
.of("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
)
|
||||
.clickEvent(ClickEvent.openUrl(
|
||||
"https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
if (pe.isAnd()) { // &
|
||||
intersectionChances.add(chance);
|
||||
intersection.add(transform);
|
||||
} else {
|
||||
if (!intersection.isEmpty()) {
|
||||
if (intersection.size() == 1) {
|
||||
throw new InputParseException(Caption.of("fawe.error.parse.invalid-dangling-character", "&"));
|
||||
}
|
||||
MultiTransform multi = new MultiTransform();
|
||||
double total = 0;
|
||||
for (int i = 0; i < intersection.size(); i++) {
|
||||
Double value = intersectionChances.get(i);
|
||||
total += value;
|
||||
multi.add(intersection.get(i), value);
|
||||
}
|
||||
union.add(multi);
|
||||
unionChances.add(total);
|
||||
intersection.clear();
|
||||
intersectionChances.clear();
|
||||
}
|
||||
unionChances.add(chance);
|
||||
union.add(transform);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new InputParseException(Caption.of(e.getMessage()), e);
|
||||
}
|
||||
if (!intersection.isEmpty()) {
|
||||
if (intersection.size() == 1) {
|
||||
throw new InputParseException(Caption.of("fawe.error.parse.invalid-dangling-character", "&"));
|
||||
}
|
||||
MultiTransform multi = new MultiTransform();
|
||||
double total = 0;
|
||||
for (int i = 0; i < intersection.size(); i++) {
|
||||
Double value = intersectionChances.get(i);
|
||||
total += value;
|
||||
multi.add(intersection.get(i), value);
|
||||
}
|
||||
union.add(multi);
|
||||
unionChances.add(total);
|
||||
intersection.clear();
|
||||
intersectionChances.clear();
|
||||
}
|
||||
if (union.isEmpty()) {
|
||||
throw new NoMatchException(Caption.of("fawe.error.parse.unknown-transform", input,
|
||||
TextComponent.of("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
).clickEvent(ClickEvent.openUrl(
|
||||
"https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/Transforms"
|
||||
))
|
||||
));
|
||||
} else if (union.size() == 1) {
|
||||
return union.get(0);
|
||||
} else {
|
||||
RandomTransform random = new RandomTransform(new TrueRandom());
|
||||
for (int i = 0; i < union.size(); i++) {
|
||||
random.add(union.get(i), unionChances.get(i));
|
||||
}
|
||||
return random;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
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;
|
||||
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RotateTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RotateTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#rotate");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
if (index == 3) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
AffineTransform transform = new AffineTransform();
|
||||
Extent extent;
|
||||
if (arguments.length == 1) {
|
||||
transform = transform.rotateY(Double.parseDouble(arguments[0]));
|
||||
extent = context.requireExtent();
|
||||
} else if (arguments.length == 3 || arguments.length == 4) {
|
||||
transform = transform.rotateX(Double.parseDouble(arguments[0]));
|
||||
transform = transform.rotateY(Double.parseDouble(arguments[1]));
|
||||
transform = transform.rotateZ(Double.parseDouble(arguments[2]));
|
||||
extent = arguments.length == 4 ? worldEdit.getTransformFactory().parseFromInput(arguments[3], context) :
|
||||
context.requireExtent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new BlockTransformExtent(extent, transform);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.ScaleTransform;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ScaleTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #scale}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public ScaleTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#scale");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
} else if (index == 3) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
double xScale;
|
||||
double yScale;
|
||||
double zScale;
|
||||
Extent extent;
|
||||
if (arguments.length == 1) {
|
||||
xScale = yScale = zScale = Double.parseDouble(arguments[0]);
|
||||
extent = context.requireExtent();
|
||||
} else if (arguments.length == 3 || arguments.length == 4) {
|
||||
xScale = Double.parseDouble(arguments[0]);
|
||||
yScale = Double.parseDouble(arguments[1]);
|
||||
zScale = Double.parseDouble(arguments[2]);
|
||||
extent = arguments.length == 4 ? worldEdit.getTransformFactory().parseFromInput(arguments[3], context) :
|
||||
context.requireExtent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new ScaleTransform(extent, xScale, yScale, zScale);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.transform;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
||||
import com.fastasyncworldedit.core.extent.transform.RandomOffsetTransform;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SpreadTransformParser extends RichParser<ResettableExtent> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public SpreadTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#spread", "#randomoffset");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
} else if (index == 3) {
|
||||
return worldEdit.getTransformFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 3 && arguments.length != 4) {
|
||||
return null;
|
||||
}
|
||||
int xOffset = Integer.parseInt(arguments[0]);
|
||||
int yOffset = Integer.parseInt(arguments[1]);
|
||||
int zOffset = Integer.parseInt(arguments[2]);
|
||||
Extent extent = arguments.length == 4 ? worldEdit.getTransformFactory().parseFromInput(arguments[3], context) :
|
||||
context.requireExtent();
|
||||
return new RandomOffsetTransform(extent, xOffset, yOffset, zOffset);
|
||||
}
|
||||
|
||||
}
|
@ -39,32 +39,6 @@ public class PrimitiveBindings extends Bindings {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Ping @MattBDev to reimplement 2020-02-04
|
||||
//
|
||||
// /**
|
||||
// * Gets an {@link Extent} from a {@link Binding}.
|
||||
// *
|
||||
// * @param argument the context
|
||||
// * @return an extent
|
||||
// * @throws InputParseException on other error
|
||||
// */
|
||||
// @Binding
|
||||
// public ResettableExtent getResettableExtent(Actor actor, String argument) throws InputParseException {
|
||||
// if (argument.equalsIgnoreCase("#null")) {
|
||||
// return new NullExtent();
|
||||
// }
|
||||
// DefaultTransformParser parser = Fawe.get().getTransformParser();
|
||||
// ParserContext parserContext = new ParserContext();
|
||||
// if (actor instanceof Entity) {
|
||||
// Extent extent = ((Entity) actor).getExtent();
|
||||
// if (extent instanceof World) {
|
||||
// parserContext.setWorld((World) extent);
|
||||
// }
|
||||
// }
|
||||
// parserContext.setSession(WorldEdit.getInstance().getSessionManager().get(actor));
|
||||
// return parser.parseFromInput(argument, parserContext);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link Binding}.
|
||||
*
|
||||
|
Reference in New Issue
Block a user