2021-07-23 15:48:51 +00:00
|
|
|
package com.fastasyncworldedit.core.extension.factory.parser.mask;
|
2020-09-06 22:42:43 +00:00
|
|
|
|
2021-08-17 16:03:25 +00:00
|
|
|
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.fastasyncworldedit.core.function.mask.WallMask;
|
2020-09-06 22:42:43 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2021-08-17 16:03:25 +00:00
|
|
|
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
2020-09-06 22:42:43 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.InputParseException;
|
|
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
2020-10-05 17:41:41 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2020-09-06 22:42:43 +00:00
|
|
|
|
2021-08-17 16:03:25 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2020-09-06 22:42:43 +00:00
|
|
|
import java.util.List;
|
2021-08-17 16:03:25 +00:00
|
|
|
import java.util.stream.Stream;
|
2020-09-06 22:42:43 +00:00
|
|
|
|
2021-08-17 16:03:25 +00:00
|
|
|
public class WallMaskParser extends RichParser<Mask> {
|
2020-09-06 22:42:43 +00:00
|
|
|
|
2021-08-17 16:03:25 +00:00
|
|
|
private final List<String> aliases = ImmutableList.of("#wall", "|");
|
2020-09-06 22:42:43 +00:00
|
|
|
|
|
|
|
public WallMaskParser(WorldEdit worldEdit) {
|
|
|
|
super(worldEdit);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getMatchedAliases() {
|
|
|
|
return aliases;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-17 16:03:25 +00:00
|
|
|
protected Stream<String> getSuggestions(final String argumentInput, final 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(@Nonnull final String[] arguments, final ParserContext context) throws InputParseException {
|
|
|
|
if (arguments.length > 3 || 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;
|
|
|
|
}
|
|
|
|
return new WallMask(subMask, min, max);
|
2020-09-06 22:42:43 +00:00
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2020-09-06 22:42:43 +00:00
|
|
|
}
|