Reformat, fix RichParser suggestions

This commit is contained in:
IronApollo 2020-09-07 21:46:54 -04:00
parent 7929320611
commit dc465f7d3c
7 changed files with 58 additions and 34 deletions

View File

@ -20,7 +20,32 @@
package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.mask.*;
import com.sk89q.worldedit.extension.factory.parser.mask.AdjacentMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.AngleMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExtremaMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ROCAngleMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.SimplexMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.SurfaceMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.TrueMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.WallMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.XAxisMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.YAxisMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ZAxisMaskParser;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;

View File

@ -36,7 +36,7 @@ public abstract class RichParser<E> extends InputParser<E> {
@Override
public Stream<String> getSuggestions(String input) {
// we don't even want to start suggesting if it's not meant to be this parser result
if (input.length() > this.required.length() && !input.startsWith(this.required)) {
if (input.length() >= this.required.length() && !input.startsWith(this.required)) {
return Stream.empty();
}
// suggest until the first [ as long as it isn't fully typed
@ -45,11 +45,11 @@ public abstract class RichParser<E> extends InputParser<E> {
}
// we know that it is at least "<required>"
String[] strings = extractArguments(input.substring(this.prefix.length()), false);
StringJoiner joiner = new StringJoiner(",");
StringBuilder builder = new StringBuilder();
for (int i = 0; i < strings.length - 1; i++) {
joiner.add("[" + strings[i] + "]");
builder.append('[').append(strings[i]).append(']');
}
String previous = this.prefix + joiner;
String previous = this.prefix + builder;
return getSuggestions(strings[strings.length - 1], strings.length - 1).map(s -> previous + "[" + s + "]");
}

View File

@ -14,12 +14,12 @@ import java.util.stream.Stream;
public class AdjacentMaskParser extends RichParser<Mask> {
public AdjacentMaskParser(WorldEdit worldEdit) {
super(worldEdit,"~");
super(worldEdit, "~");
}
@Override
protected Stream<String> getSuggestions(String argumentInput, int index) {
if(index == 0){
if (index == 0) {
return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
} else if (index == 1 || index == 2) {
return this.suggestPositiveDoubles(argumentInput);
@ -29,7 +29,7 @@ public class AdjacentMaskParser extends RichParser<Mask> {
@Override
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
if(arguments.length == 0) return null;
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;
@ -40,6 +40,6 @@ public class AdjacentMaskParser extends RichParser<Mask> {
if (max >= 8 && min == 1) {
return new AdjacentAnyMask(subMask);
}
return new AdjacentMask(subMask, (int) min, (int) max);
return new AdjacentMask(subMask, min, max);
}
}

View File

@ -18,7 +18,7 @@ public class RadiusMaskParser extends RichParser<Mask> {
@Override
protected Stream<String> getSuggestions(String argumentInput, int index) {
if(index == 0 || index == 1){
if (index == 0 || index == 1) {
return suggestPositiveDoubles(argumentInput);
}
return Stream.empty();
@ -26,10 +26,9 @@ public class RadiusMaskParser extends RichParser<Mask> {
@Override
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
if(arguments.length < 2) return null;
if (arguments.length < 2) return null;
int min = Integer.parseInt(arguments[0]);
int max = Integer.parseInt(arguments[1]);
System.out.println("radius: " + min + " | " + max);
return new RadiusMask(min, max);
}
}