3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 10:30:04 +01:00

Improve mask parsing

- Fixes #1230
Dieser Commit ist enthalten in:
dordsor21 2021-08-17 17:02:11 +01:00
Ursprung f6676cf6a3
Commit 46f6395279
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
9 geänderte Dateien mit 165 neuen und 72 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -108,11 +109,11 @@ public class RichMaskParser extends FaweParser<Mask> {
// Legacy syntax
if (charMask) {
switch (char0) {
case '\\': //
case '/': //
case '{': //
case '$': //
case '%': {
case '\\':
case '/':
case '{':
case '|':
case '~': {
String value = command.substring(1) + ((entry.getValue().isEmpty())
? ""
: "[" + StringMan.join(
@ -125,23 +126,16 @@ public class RichMaskParser extends FaweParser<Mask> {
}
value = value.replaceAll(":", "][");
}
mask = parseFromInput("#" + char0 + "[" + value + "]", context);
mask = parseFromInput(char0 + "[" + value + "]", context);
break;
}
case '|':
case '~':
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;
}
}
@ -154,6 +148,26 @@ public class RichMaskParser extends FaweParser<Mask> {
try {
builder.addRegex(full);
} catch (InputParseException ignored) {
} catch (PatternSyntaxException e) {
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)));
}
);
}
context.setPreferringWildcard(false);
context.setRestricted(false);

Datei anzeigen

@ -1,46 +0,0 @@
package com.fastasyncworldedit.core.function.mask;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;
public class IdDataMask extends AbstractExtentMask implements ResettableMask {
private transient int combined = -1;
public IdDataMask(Extent extent) {
super(extent);
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
if (combined != -1) {
return getExtent().getBlock(vector).getInternalId() == combined;
} else {
combined = getExtent().getBlock(vector).getInternalId();
return true;
}
}
@Override
public boolean test(BlockVector3 vector) {
return test(getExtent(), vector);
}
@Override
public void reset() {
this.combined = -1;
}
@Override
public Mask copy() {
return new IdDataMask(getExtent());
}
@Override
public boolean replacesAir() {
return true;
}
}

Datei anzeigen

@ -20,7 +20,10 @@
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
import com.fastasyncworldedit.core.util.StringMan;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.SuggestionHelper;
import com.sk89q.worldedit.extension.input.InputParseException;
@ -33,12 +36,18 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.biome.BiomeType;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class BiomeMaskParser extends InputParser<Mask> {
//FAWE start - aliased
public class BiomeMaskParser extends InputParser<Mask> implements AliasedParser {
private final List<String> aliases = ImmutableList.of("$");
//FAWE end
public BiomeMaskParser(WorldEdit worldEdit) {
super(worldEdit);
@ -70,8 +79,22 @@ public class BiomeMaskParser extends InputParser<Mask> {
return null;
}
//FAWE start - richer parsing
if (input.charAt(1) == '[') {
int end = input.lastIndexOf(']');
if (end == -1) {
return null;
}
input = input.substring(2, end);
} else {
input = input.substring(1);
}
//FAWE end
Set<BiomeType> biomes = new HashSet<>();
for (String biomeName : Splitter.on(",").split(input.substring(1))) {
//FAWE start - richer parsing
for (String biomeName : Splitter.on(",").split(input)) {
//FAWE end
BiomeType biome = BiomeType.REGISTRY.get(biomeName);
if (biome == null) {
throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(biomeName)));
@ -82,4 +105,11 @@ public class BiomeMaskParser extends InputParser<Mask> {
return new BiomeMask(context.requireExtent(), biomes);
}
//FAWE start - aliased
@Override
public List<String> getMatchedAliases() {
return aliases;
}
//FAWE end
}

Datei anzeigen

@ -20,7 +20,9 @@
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
import com.google.common.base.Splitter;
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;
@ -29,9 +31,14 @@ import com.sk89q.worldedit.function.mask.Mask;
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 BlockStateMaskParser extends InputParser<Mask> {
//FAWE start - aliased
public class BlockStateMaskParser extends InputParser<Mask> implements AliasedParser {
private final List<String> aliases = ImmutableList.of("^", "^=");
//FAWE end
public BlockStateMaskParser(WorldEdit worldEdit) {
super(worldEdit);
@ -67,4 +74,11 @@ public class BlockStateMaskParser extends InputParser<Mask> {
}
}
//FAWE start - aliased
@Override
public List<String> getMatchedAliases() {
return aliases;
}
//FAWE end
}

Datei anzeigen

@ -20,6 +20,8 @@
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
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;
@ -33,10 +35,15 @@ import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
import com.sk89q.worldedit.session.SessionOwner;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import java.util.List;
import java.util.function.IntSupplier;
import java.util.stream.Stream;
public class ExpressionMaskParser extends InputParser<Mask> {
//FAWE start - aliased
public class ExpressionMaskParser extends InputParser<Mask> implements AliasedParser {
private final List<String> aliases = ImmutableList.of("=");
//FAWE end
public ExpressionMaskParser(WorldEdit worldEdit) {
super(worldEdit);
@ -56,8 +63,22 @@ public class ExpressionMaskParser extends InputParser<Mask> {
return null;
}
//FAWE start - richer parsing
if (input.charAt(1) == '[') {
int end = input.lastIndexOf(']');
if (end == -1) {
return null;
}
input = input.substring(2, end);
} else {
input = input.substring(1);
}
//FAWE end
try {
Expression exp = Expression.compile(input.substring(1), "x", "y", "z");
//FAWE start - richer parsing
Expression exp = Expression.compile(input, "x", "y", "z");
//FAWE end
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
context.requireExtent(), Vector3.ONE, Vector3.ZERO);
exp.setEnvironment(env);
@ -75,4 +96,11 @@ public class ExpressionMaskParser extends InputParser<Mask> {
}
}
//FAWE start - aliased
@Override
public List<String> getMatchedAliases() {
return aliases;
}
//FAWE end
}

Datei anzeigen

@ -20,6 +20,8 @@
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
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;
@ -27,9 +29,14 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.registry.InputParser;
import java.util.List;
import java.util.stream.Stream;
public class NegateMaskParser extends InputParser<Mask> {
//FAWE start - aliased
public class NegateMaskParser extends InputParser<Mask> implements AliasedParser {
private final List<String> aliases = ImmutableList.of("!");
//FAWE end
public NegateMaskParser(WorldEdit worldEdit) {
super(worldEdit);
@ -59,4 +66,11 @@ public class NegateMaskParser extends InputParser<Mask> {
}
}
//FAWE start - aliased
@Override
public List<String> getMatchedAliases() {
return aliases;
}
//FAWE end
}

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
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;
@ -26,9 +28,14 @@ import com.sk89q.worldedit.function.mask.NoiseFilter;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.noise.RandomNoise;
import java.util.List;
import java.util.stream.Stream;
public class NoiseMaskParser extends InputParser<Mask> {
//FAWE start - aliased
public class NoiseMaskParser extends InputParser<Mask> implements AliasedParser {
private final List<String> aliases = ImmutableList.of("%");
//FAWE end
public NoiseMaskParser(WorldEdit worldEdit) {
super(worldEdit);
@ -51,8 +58,28 @@ public class NoiseMaskParser extends InputParser<Mask> {
return null;
}
int i = Integer.parseInt(input.substring(1));
//FAWE start - richer parsing
if (input.charAt(1) == '[') {
int end = input.lastIndexOf(']');
if (end == -1) {
return null;
}
input = input.substring(2, end);
} else {
input = input.substring(1);
}
int i = Integer.parseInt(input);
//FAWE end
return new NoiseFilter(new RandomNoise(), ((double) i) / 100);
}
//FAWE start - aliased
@Override
public List<String> getMatchedAliases() {
return aliases;
}
//FAWE end
}

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
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;
@ -28,9 +30,14 @@ import com.sk89q.worldedit.function.mask.OffsetMask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import java.util.List;
import java.util.stream.Stream;
public class OffsetMaskParser extends InputParser<Mask> {
//FAWE start - aliased
public class OffsetMaskParser extends InputParser<Mask> implements AliasedParser {
private final List<String> aliases = ImmutableList.of(">", "<");
//FAWE end
public OffsetMaskParser(WorldEdit worldEdit) {
super(worldEdit);
@ -66,4 +73,11 @@ public class OffsetMaskParser extends InputParser<Mask> {
//FAWE end
}
//FAWE start - aliased
@Override
public List<String> getMatchedAliases() {
return aliases;
}
//FAWE end
}

Datei anzeigen

@ -90,8 +90,6 @@
"fawe.worldedit.selector.selector.fuzzy.pos1": "Region set and expanded from {0} {1}.",
"fawe.worldedit.selector.selector.fuzzy.pos2": "Added expansion of {0} {1}.",
"fawe.worldedit.help.command.clarifying.bracket": "Added clarifying bracket for {0}",
"fawe.progress.progress.message": "{1}/{0} ({2}%) @{3}cps {4}s left",
"fawe.progress.progress.finished": "[ Done! ]",