Fix parsing for injected command types

Dieser Commit ist enthalten in:
Jesse Boyd 2019-11-11 08:55:53 +00:00
Ursprung 10a6619853
Commit 9d6f2df908
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
7 geänderte Dateien mit 39 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -8,21 +8,31 @@ 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.internal.registry.InputParser;
import org.enginehub.piston.inject.InjectedValueAccess;
import java.util.*;
public abstract class FaweParser<T> extends InputParser<T> {
protected FaweParser(WorldEdit worldEdit) {
private final String prefix;
protected FaweParser(WorldEdit worldEdit, String prefix) {
super(worldEdit);
this.prefix = prefix;
}
public PlatformCommandManager getPlatform() {
return PlatformCommandManager.getInstance();
}
public T parse(String input, Actor actor) {
return getPlatform().parse("pattern " + input, actor);
public T parse(String input, ParserContext context) {
input = prefix + " " + input;
InjectedValueAccess injected = context.getInjected();
if (injected != null) {
return getPlatform().parse(input, injected);
} else {
return getPlatform().parse(input, context.getActor());
}
}
public T catchSuggestion(String currentInput, String nextInput, ParserContext context) throws InputParseException {

Datei anzeigen

@ -116,6 +116,7 @@ public class FactoryConverter<T> implements ArgumentConverter<T> {
}
parserContext.setSession(session);
parserContext.setRestricted(true);
parserContext.setInjected(context);
if (contextTweaker != null) {
contextTweaker.accept(parserContext);

Datei anzeigen

@ -23,7 +23,7 @@ import java.util.Map;
public class DefaultTransformParser extends FaweParser<ResettableExtent> {
public DefaultTransformParser(WorldEdit worldEdit) {
super(worldEdit);
super(worldEdit, "transforms");
}
@Override
@ -53,7 +53,7 @@ public class DefaultTransformParser extends FaweParser<ResettableExtent> {
List<String> args = entry.getValue();
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
try {
transform = parse(cmdArgs, actor);
transform = parse(command + cmdArgs, context);
} catch (SuggestInputParseException rethrow) {
throw rethrow;
} catch (Throwable e) {

Datei anzeigen

@ -49,7 +49,7 @@ import java.util.stream.Stream;
public class DefaultMaskParser extends FaweParser<Mask> {
public DefaultMaskParser(WorldEdit worldEdit) {
super(worldEdit);
super(worldEdit, "masks");
}
@Override
@ -80,7 +80,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
List<String> args = entry.getValue();
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
try {
mask = parse(cmdArgs, actor);
mask = parse(command + cmdArgs, context);
} catch (SuggestInputParseException rethrow) {
throw rethrow;
} catch (Throwable e) {

Datei anzeigen

@ -30,6 +30,7 @@ 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;
@ -44,7 +45,7 @@ import java.util.stream.Stream;
public class DefaultPatternParser extends FaweParser<Pattern> {
public DefaultPatternParser(WorldEdit worldEdit) {
super(worldEdit);
super(worldEdit, "patterns");
}
@Override
@ -72,7 +73,7 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
List<String> args = entry.getValue();
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
try {
pattern = parse(cmdArgs, actor);
pattern = parse(command + cmdArgs, context);
} catch (SuggestInputParseException rethrow) {
throw rethrow;
} catch (Throwable e) {

Datei anzeigen

@ -24,6 +24,7 @@ import com.sk89q.worldedit.extension.factory.MaskFactory;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.inject.InjectedValueAccess;
import javax.annotation.Nullable;
@ -42,6 +43,7 @@ public class ParserContext {
private boolean restricted = true;
private boolean tryLegacy = true;
private boolean preferringWildcard;
private InjectedValueAccess injected;
/**
* Create a new instance.
@ -248,4 +250,12 @@ public class ParserContext {
public boolean isTryingLegacy() {
return tryLegacy;
}
public void setInjected(InjectedValueAccess injected) {
this.injected = injected;
}
public InjectedValueAccess getInjected() {
return injected;
}
}

Datei anzeigen

@ -609,10 +609,17 @@ public final class PlatformCommandManager {
}
public <T> T parse(String args, Actor actor) {
return parse(args, actor);
InjectedValueAccess context;
if (actor == null) {
context = globalInjectedValues;
} else {
context = initializeInjectedValues(args::toString, actor);
}
return parse(args, context);
}
public <T> T parse(String args, InjectedValueAccess access) {
if (args.isEmpty()) return null;
String[] split = parseArgs(args)
.map(Substring::getSubstring)
.toArray(String[]::new);