mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:14:04 +00:00
Feature/propagate diff and object cleanup (#1190)
* Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit275ba9bd84
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit9fd8984804
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit861fb45e5c
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit420c45a29a
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit4d4db7dcd0
Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commitc98f6e4f37
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit2485f5eccc
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commitd9418ec8ae
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of41073bb1a0
Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
// 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,150 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.google.common.base.Preconditions;
|
||||
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 com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A rich parser allows parsing of patterns and masks with extra arguments,
|
||||
* e.g. #simplex[scale][pattern].
|
||||
*
|
||||
* @param <E> the parse result.
|
||||
*/
|
||||
public abstract class RichParser<E> extends InputParser<E> {
|
||||
private final String[] prefixes;
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
* @param aliases the prefix of this parser result.
|
||||
*/
|
||||
protected RichParser(WorldEdit worldEdit, String... aliases) {
|
||||
super(worldEdit);
|
||||
Preconditions.checkArgument(aliases.length >= 1, "Aliases may not be empty");
|
||||
this.prefixes = aliases;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Predicate<String> validPrefix(String other) {
|
||||
return prefix -> {
|
||||
if (prefix.length() > other.length()) {
|
||||
return prefix.startsWith(other);
|
||||
}
|
||||
return other.startsWith(prefix);
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Function<String, Stream<? extends String>> extractArguments(String input) {
|
||||
return prefix -> {
|
||||
if (input.length() > prefix.length()) {
|
||||
// input already contains argument(s) -> extract them
|
||||
String[] strings = extractArguments(input.substring(prefix.length()), false);
|
||||
// rebuild the argument string without the last argument
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < strings.length - 1; i++) {
|
||||
builder.append('[').append(strings[i]).append(']');
|
||||
}
|
||||
String previous = prefix + builder;
|
||||
// read the suggestions for the last argument
|
||||
return getSuggestions(strings[strings.length - 1], strings.length - 1)
|
||||
.map(suggestion -> previous + "[" + suggestion);
|
||||
} else {
|
||||
return Stream.of(prefix);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefixes[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return Arrays.stream(this.prefixes)
|
||||
.filter(validPrefix(input))
|
||||
.flatMap(extractArguments(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public E parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
for (String prefix : this.prefixes) {
|
||||
if (!input.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
if (input.length() < prefix.length()) {
|
||||
continue;
|
||||
}
|
||||
String[] arguments = extractArguments(input.substring(prefix.length()), true);
|
||||
return parseFromInput(arguments, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for the argument at the given index.
|
||||
*
|
||||
* @param argumentInput the already provided input for the argument at the given index.
|
||||
* @param index the index of the argument to get suggestions for.
|
||||
* @return a stream of suggestions matching the given input for the argument at the given index.
|
||||
*/
|
||||
protected abstract Stream<String> getSuggestions(String argumentInput, int index);
|
||||
|
||||
/**
|
||||
* Parses the already split arguments.
|
||||
*
|
||||
* @param arguments the array of arguments that were split (can be empty).
|
||||
* @param context the context of this parsing process.
|
||||
* @return the resulting parsed type.
|
||||
* @throws InputParseException if the input couldn't be parsed correctly.
|
||||
*/
|
||||
protected abstract E parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException;
|
||||
|
||||
/**
|
||||
* Extracts arguments enclosed by {@code []} into an array.
|
||||
* Example: {@code [Hello][World]} results in a list containing {@code Hello} and {@code World}.
|
||||
*
|
||||
* @param input the input to extract arguments from.
|
||||
* @param requireClosing whether or not the extraction requires valid bracketing.
|
||||
* @return an array of extracted arguments.
|
||||
* @throws InputParseException if {@code requireClosing == true} and the count of [ != the count of ]
|
||||
*/
|
||||
protected String[] extractArguments(String input, boolean requireClosing) throws InputParseException {
|
||||
int open = 0; // the "level"
|
||||
int openIndex = 0;
|
||||
int i = 0;
|
||||
List<String> arguments = new ArrayList<>();
|
||||
for (; i < input.length(); i++) {
|
||||
if (input.charAt(i) == '[') {
|
||||
if (open++ == 0) {
|
||||
openIndex = i;
|
||||
}
|
||||
}
|
||||
if (input.charAt(i) == ']') {
|
||||
if (--open == 0) {
|
||||
arguments.add(input.substring(openIndex + 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!requireClosing && open > 0) {
|
||||
arguments.add(input.substring(openIndex + 1));
|
||||
}
|
||||
if (requireClosing && open != 0) {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-bracketing", TextComponent.of("'[' or ']'?")));
|
||||
}
|
||||
return arguments.toArray(new String[0]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.AdjacentAnyMask;
|
||||
import com.fastasyncworldedit.core.function.mask.AdjacentMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AdjacentMaskParser extends RichParser<Mask> {
|
||||
|
||||
public AdjacentMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "~");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
|
||||
} else if (index == 1 || index == 2) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Mask subMask = worldEdit.getMaskFactory().parseFromInput(arguments[0], context);
|
||||
int min = arguments.length > 1 ? Integer.parseInt(arguments[1]) : -1;
|
||||
int max = arguments.length > 2 ? Integer.parseInt(arguments[2]) : -1;
|
||||
if (min == -1 && max == -1) {
|
||||
min = 1;
|
||||
max = 8;
|
||||
} else if (max == -1) {
|
||||
max = min;
|
||||
}
|
||||
if (max >= 8 && min == 1) {
|
||||
return new AdjacentAnyMask(subMask);
|
||||
}
|
||||
return new AdjacentMask(subMask, min, max);
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.mask.AngleMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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.util.formatting.text.TextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AngleMaskParser extends RichParser<Mask> {
|
||||
|
||||
private final String[] flags = new String[]{"-o"};
|
||||
|
||||
public AngleMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2 || arguments.length > 2 + flags.length) {
|
||||
return null;
|
||||
}
|
||||
String minArg = arguments[0];
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException(Caption.of("fawe.error.mask.angle"));
|
||||
}
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
for (int index = 2; index < 2 + flags.length; index++) {
|
||||
String flag = arguments[index];
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
if (degree) {
|
||||
double minDeg = Double.parseDouble(minArg.substring(0, minArg.length() - 1));
|
||||
double maxDeg = Double.parseDouble(maxArg.substring(0, maxArg.length() - 1));
|
||||
min = (Math.tan(minDeg * (Math.PI / 180)));
|
||||
max = (Math.tan(maxDeg * (Math.PI / 180)));
|
||||
} else {
|
||||
min = Double.parseDouble(minArg);
|
||||
max = Double.parseDouble(maxArg);
|
||||
}
|
||||
|
||||
return new AngleMask(context.getExtent(), min, max, overlay, 1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
// 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,71 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.mask.ExtremaMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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.util.formatting.text.TextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ExtremaMaskParser extends RichParser<Mask> {
|
||||
|
||||
private final String[] flags = new String[]{"-o"};
|
||||
|
||||
public ExtremaMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#extrema");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2 || arguments.length > 2 + flags.length) {
|
||||
return null;
|
||||
}
|
||||
String minArg = arguments[0];
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException(Caption.of("fawe.error.mask.angle"));
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
for (int index = 2; index < 2 + flags.length; index++) {
|
||||
String flag = arguments[index];
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (degree) {
|
||||
double minDeg = Double.parseDouble(minArg.substring(0, minArg.length() - 1));
|
||||
double maxDeg = Double.parseDouble(maxArg.substring(0, maxArg.length() - 1));
|
||||
min = (Math.tan(minDeg * (Math.PI / 180)));
|
||||
max = (Math.tan(maxDeg * (Math.PI / 180)));
|
||||
} else {
|
||||
min = Double.parseDouble(minArg);
|
||||
max = Double.parseDouble(maxArg);
|
||||
}
|
||||
|
||||
return new ExtremaMask(context.getExtent(), min, max, overlay, 4);
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FalseMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#false");
|
||||
|
||||
public FalseMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return Masks.alwaysFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.LiquidMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LiquidMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#liquid");
|
||||
|
||||
public LiquidMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new LiquidMask(context.getExtent());
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.mask.ROCAngleMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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.util.formatting.text.TextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ROCAngleMaskParser extends RichParser<Mask> {
|
||||
|
||||
private final String[] flags = new String[]{"-o"};
|
||||
|
||||
public ROCAngleMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#roc");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2 || arguments.length > 2 + flags.length) {
|
||||
return null;
|
||||
}
|
||||
String minArg = arguments[0];
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException(Caption.of("fawe.error.mask.angle"));
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
for (int index = 2; index < 2 + flags.length; index++) {
|
||||
String flag = arguments[index];
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (degree) {
|
||||
double minDeg = Double.parseDouble(minArg.substring(0, minArg.length() - 1));
|
||||
double maxDeg = Double.parseDouble(maxArg.substring(0, maxArg.length() - 1));
|
||||
min = (Math.tan(minDeg * (Math.PI / 180)));
|
||||
max = (Math.tan(maxDeg * (Math.PI / 180)));
|
||||
} else {
|
||||
min = Double.parseDouble(minArg);
|
||||
max = Double.parseDouble(maxArg);
|
||||
}
|
||||
|
||||
return new ROCAngleMask(context.getExtent(), min, max, overlay, 4);
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.RadiusMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RadiusMaskParser extends RichParser<Mask> {
|
||||
|
||||
public RadiusMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "{");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2) {
|
||||
return null;
|
||||
}
|
||||
int min = Integer.parseInt(arguments[0]);
|
||||
int max = Integer.parseInt(arguments[1]);
|
||||
return new RadiusMask(min, max);
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.mask.OffsetMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RichOffsetMaskParser extends RichParser<Mask> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RichOffsetMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#offset");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
}
|
||||
if (index == 3) {
|
||||
return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 4) {
|
||||
return null;
|
||||
}
|
||||
int x = Integer.parseInt(arguments[0]);
|
||||
int y = Integer.parseInt(arguments[1]);
|
||||
int z = Integer.parseInt(arguments[2]);
|
||||
Mask submask = worldEdit.getMaskFactory().parseFromInput(arguments[3], context);
|
||||
OffsetMask offsetMask = new OffsetMask(submask, BlockVector3.at(x, y, z));
|
||||
return new MaskIntersection(offsetMask, Masks.negate(submask));
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.SimplexMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SimplexMaskParser extends RichParser<Mask> {
|
||||
private static final String SIMPLEX_PREFIX = "#simplex";
|
||||
|
||||
public SimplexMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, SIMPLEX_PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 3) {
|
||||
return null;
|
||||
}
|
||||
double scale = Double.parseDouble(arguments[0]);
|
||||
double min = Double.parseDouble(arguments[1]);
|
||||
double max = Double.parseDouble(arguments[2]);
|
||||
scale = 1d / Math.max(1d, scale);
|
||||
min = (min - 50d) / 50d;
|
||||
max = (max - 50d) / 50d;
|
||||
return new SimplexMask(scale, min, max);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.SurfaceMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SurfaceMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#surface");
|
||||
|
||||
public SurfaceMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new SurfaceMask(context.getExtent());
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrueMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#true");
|
||||
|
||||
public TrueMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return Masks.alwaysTrue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.WallMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WallMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#wall");
|
||||
|
||||
public WallMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new MaskIntersection(new ExistingBlockMask(context.getExtent()), new WallMask(new BlockMask(context.getExtent(), BlockTypes.AIR.getDefaultState().toBaseBlock()), 1, 8));
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.XAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class XAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#xaxis");
|
||||
|
||||
public XAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new XAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.YAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#yaxis");
|
||||
|
||||
public YAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new YAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.function.mask.ZAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ZAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#zaxis");
|
||||
|
||||
public ZAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new ZAxisMask();
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.pattern.BiomeApplyingPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BiomePatternParser extends RichParser<Pattern> {
|
||||
private final static String BIOME_PREFIX = "$";
|
||||
|
||||
/**
|
||||
* Create a new biome pattern parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public BiomePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#biome");
|
||||
}
|
||||
|
||||
// overridden to provide $<biome> too
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (input.startsWith(BIOME_PREFIX)) {
|
||||
String biomeId = input.substring(1);
|
||||
BiomeType biomeType = BiomeTypes.get(biomeId);
|
||||
if (biomeType == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(biomeId)));
|
||||
}
|
||||
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
|
||||
} else {
|
||||
return super.parseFromInput(input, context);
|
||||
}
|
||||
}
|
||||
|
||||
// overridden to provide $<biome> too
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.startsWith(BIOME_PREFIX)) {
|
||||
return BiomeType.REGISTRY.getSuggestions(input.substring(1)).map(biome -> BIOME_PREFIX + biome);
|
||||
} else {
|
||||
return super.getSuggestions(input);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return BiomeType.REGISTRY.getSuggestions(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-arguments", TextComponent.of("#biome[<biome>]")));
|
||||
}
|
||||
BiomeType biomeType = BiomeTypes.get(arguments[0]);
|
||||
if (biomeType == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(arguments[0])));
|
||||
}
|
||||
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.pattern.BufferedPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BufferedPatternParser 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 BufferedPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#buffer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull 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);
|
||||
return new BufferedPattern(context.requireActor(), inner);
|
||||
}
|
||||
}
|
@@ -0,0 +1,167 @@
|
||||
// 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,29 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.function.pattern.ExistingPattern;
|
||||
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 ExistingPatternParser extends SimpleInputParser<Pattern> {
|
||||
private final List<String> aliases = Collections.singletonList("#existing");
|
||||
|
||||
public ExistingPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new ExistingPattern(context.requireExtent());
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.pattern.Linear2DBlockPattern;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear2DPatternParser 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 Linear2DPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear2d", "#l2d");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull 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() + "[stone,dirt])")));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (inner instanceof BlockStateHolder) {
|
||||
return inner;
|
||||
}
|
||||
int xScale = 1;
|
||||
int zScale = 1;
|
||||
if (arguments.length > 1) {
|
||||
xScale = Integer.parseInt(arguments[1]);
|
||||
Preconditions.checkArgument(xScale != 0);
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
zScale = Integer.parseInt(arguments[2]);
|
||||
Preconditions.checkArgument(zScale != 0);
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new Linear2DBlockPattern(patterns.toArray(new Pattern[0]), xScale, zScale);
|
||||
}
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.function.pattern.Linear3DBlockPattern;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear3DPatternParser 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 Linear3DPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear3d", "#l3d");
|
||||
}
|
||||
|
||||
@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(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length == 0 || arguments.length > 4) {
|
||||
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;
|
||||
}
|
||||
int xScale = 1;
|
||||
int yScale = 1;
|
||||
int zScale = 1;
|
||||
if (arguments.length > 1) {
|
||||
xScale = Integer.parseInt(arguments[1]);
|
||||
Preconditions.checkArgument(xScale != 0);
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
yScale = Integer.parseInt(arguments[2]);
|
||||
Preconditions.checkArgument(yScale != 0);
|
||||
}
|
||||
if (arguments.length > 3) {
|
||||
zScale = Integer.parseInt(arguments[3]);
|
||||
Preconditions.checkArgument(zScale != 0);
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new Linear3DBlockPattern(patterns.toArray(new Pattern[0]), xScale, yScale,zScale);
|
||||
}
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.math.random.NoiseRandom;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
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.math.noise.NoiseGenerator;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class NoisePatternParser extends RichParser<Pattern> {
|
||||
|
||||
private final String name;
|
||||
private final Supplier<NoiseGenerator> generatorSupplier;
|
||||
|
||||
/**
|
||||
* Create a new noise parser with a defined name, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
* @param name the name of this noise.
|
||||
* @param generatorSupplier the supplier to get a {@link NoiseGenerator} instance from.
|
||||
*/
|
||||
protected NoisePatternParser(WorldEdit worldEdit, String name, Supplier<NoiseGenerator> generatorSupplier) {
|
||||
super(worldEdit, '#' + name);
|
||||
this.name = name;
|
||||
this.generatorSupplier = generatorSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
if (index == 1) {
|
||||
return worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) {
|
||||
if (arguments.length != 2) {
|
||||
throw new InputParseException(Caption.of("fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[scale][pattern] (e.g. " + getPrefix() + "[5][dirt,stone])")));
|
||||
}
|
||||
double scale = parseScale(arguments[0]);
|
||||
Pattern inner = worldEdit.getPatternFactory().parseFromInput(arguments[1], context);
|
||||
if (inner instanceof RandomPattern) {
|
||||
return new RandomPattern(new NoiseRandom(this.generatorSupplier.get(), scale), (RandomPattern) inner);
|
||||
} else if (inner instanceof BlockStateHolder) {
|
||||
return inner; // single blocks won't have any impact on how a noise behaves
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with #" + this.name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the given argument to match the requirements of the noise generator.
|
||||
*
|
||||
* @param argument the parsed scale argument.
|
||||
* @return the modified scale.
|
||||
*/
|
||||
protected double parseScale(String argument) {
|
||||
double scale = Double.parseDouble(argument);
|
||||
return 1d / Math.max(1, scale);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.PerlinNoise;
|
||||
|
||||
public class PerlinPatternParser extends NoisePatternParser {
|
||||
private static final String PERLIN_NAME = "perlin";
|
||||
|
||||
/**
|
||||
* Create a new perlin noise parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public PerlinPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, PERLIN_NAME, PerlinNoise::new);
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
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.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomPatternParser extends InputParser<Pattern> {
|
||||
|
||||
public RandomPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
List<String> patterns = StringUtil.split(input, ',', '[', ']');
|
||||
/*String[] splits = input.split(",", -1);
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']', true);*/
|
||||
if (patterns.size() == 1) {
|
||||
return Stream.empty();
|
||||
}
|
||||
// get suggestions for the last token only
|
||||
String token = patterns.get(patterns.size() - 1);
|
||||
String previous = String.join(",", patterns.subList(0, patterns.size() - 1));
|
||||
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
|
||||
String[] p = token.split("%");
|
||||
|
||||
if (p.length < 2) {
|
||||
return Stream.empty();
|
||||
} else {
|
||||
token = p[1];
|
||||
}
|
||||
}
|
||||
final List<String> innerSuggestions = worldEdit.getPatternFactory().getSuggestions(token);
|
||||
return innerSuggestions.stream().map(s -> previous + "," + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
RandomPattern randomPattern = new RandomPattern();
|
||||
|
||||
List<String> patterns = StringUtil.split(input, ',', '[', ']');
|
||||
/*String[] splits = input.split(",", -1);
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']', true);*/
|
||||
if (patterns.size() == 1) {
|
||||
return null; // let a 'single'-pattern parser handle it
|
||||
}
|
||||
for (String token : patterns) {
|
||||
double chance;
|
||||
Pattern innerPattern;
|
||||
|
||||
// Parse special percentage syntax
|
||||
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
|
||||
String[] p = token.split("%", 2);
|
||||
|
||||
if (p.length < 2) {
|
||||
throw new InputParseException(Caption.of("worldedit.error.parser.missing-random-type", TextComponent.of(input)));
|
||||
} else {
|
||||
chance = Double.parseDouble(p[0]);
|
||||
innerPattern = worldEdit.getPatternFactory().parseFromInput(p[1], context);
|
||||
}
|
||||
} else {
|
||||
chance = 1;
|
||||
innerPattern = worldEdit.getPatternFactory().parseFromInput(token, context);
|
||||
}
|
||||
|
||||
randomPattern.add(innerPattern, chance);
|
||||
}
|
||||
|
||||
return randomPattern;
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise;
|
||||
|
||||
public class RidgedMultiFractalPatternParser extends NoisePatternParser {
|
||||
|
||||
private static final String RIDGED_MULTI_FRACTAL_NAME = "rmf";
|
||||
|
||||
/**
|
||||
* Create a new ridged multi fractal noise parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RidgedMultiFractalPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, RIDGED_MULTI_FRACTAL_NAME, RidgedMultiFractalNoise::new);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.fastasyncworldedit.core.math.random.SimplexNoiseGenerator;
|
||||
|
||||
public class SimplexPatternParser extends NoisePatternParser {
|
||||
private static final String SIMPLEX_NAME = "simplex";
|
||||
|
||||
public SimplexPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, SIMPLEX_NAME, SimplexNoiseGenerator::new);
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.VoronoiNoise;
|
||||
|
||||
public class VoronoiPatternParser extends NoisePatternParser {
|
||||
|
||||
private static final String VORONOI_NAME = "voronoi";
|
||||
|
||||
/**
|
||||
* Create a new voronoi noise parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public VoronoiPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, VORONOI_NAME, VoronoiNoise::new);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user