geforkt von Mirrors/FastAsyncWorldEdit
Fix parsing for injected command types
Dieser Commit ist enthalten in:
Ursprung
10a6619853
Commit
9d6f2df908
@ -8,21 +8,31 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||||
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public abstract class FaweParser<T> extends InputParser<T> {
|
public abstract class FaweParser<T> extends InputParser<T> {
|
||||||
|
|
||||||
protected FaweParser(WorldEdit worldEdit) {
|
private final String prefix;
|
||||||
|
|
||||||
|
protected FaweParser(WorldEdit worldEdit, String prefix) {
|
||||||
super(worldEdit);
|
super(worldEdit);
|
||||||
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlatformCommandManager getPlatform() {
|
public PlatformCommandManager getPlatform() {
|
||||||
return PlatformCommandManager.getInstance();
|
return PlatformCommandManager.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T parse(String input, Actor actor) {
|
public T parse(String input, ParserContext context) {
|
||||||
return getPlatform().parse("pattern " + input, actor);
|
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 {
|
public T catchSuggestion(String currentInput, String nextInput, ParserContext context) throws InputParseException {
|
||||||
|
@ -116,6 +116,7 @@ public class FactoryConverter<T> implements ArgumentConverter<T> {
|
|||||||
}
|
}
|
||||||
parserContext.setSession(session);
|
parserContext.setSession(session);
|
||||||
parserContext.setRestricted(true);
|
parserContext.setRestricted(true);
|
||||||
|
parserContext.setInjected(context);
|
||||||
|
|
||||||
if (contextTweaker != null) {
|
if (contextTweaker != null) {
|
||||||
contextTweaker.accept(parserContext);
|
contextTweaker.accept(parserContext);
|
||||||
|
@ -23,7 +23,7 @@ import java.util.Map;
|
|||||||
public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
||||||
|
|
||||||
public DefaultTransformParser(WorldEdit worldEdit) {
|
public DefaultTransformParser(WorldEdit worldEdit) {
|
||||||
super(worldEdit);
|
super(worldEdit, "transforms");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,7 +53,7 @@ public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
|||||||
List<String> args = entry.getValue();
|
List<String> args = entry.getValue();
|
||||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||||
try {
|
try {
|
||||||
transform = parse(cmdArgs, actor);
|
transform = parse(command + cmdArgs, context);
|
||||||
} catch (SuggestInputParseException rethrow) {
|
} catch (SuggestInputParseException rethrow) {
|
||||||
throw rethrow;
|
throw rethrow;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -49,7 +49,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class DefaultMaskParser extends FaweParser<Mask> {
|
public class DefaultMaskParser extends FaweParser<Mask> {
|
||||||
public DefaultMaskParser(WorldEdit worldEdit) {
|
public DefaultMaskParser(WorldEdit worldEdit) {
|
||||||
super(worldEdit);
|
super(worldEdit, "masks");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,7 +80,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
|
|||||||
List<String> args = entry.getValue();
|
List<String> args = entry.getValue();
|
||||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||||
try {
|
try {
|
||||||
mask = parse(cmdArgs, actor);
|
mask = parse(command + cmdArgs, context);
|
||||||
} catch (SuggestInputParseException rethrow) {
|
} catch (SuggestInputParseException rethrow) {
|
||||||
throw rethrow;
|
throw rethrow;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -30,6 +30,7 @@ import com.sk89q.worldedit.extension.input.InputParseException;
|
|||||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
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.Pattern;
|
||||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||||
import com.sk89q.worldedit.internal.expression.Expression;
|
import com.sk89q.worldedit.internal.expression.Expression;
|
||||||
@ -44,7 +45,7 @@ import java.util.stream.Stream;
|
|||||||
public class DefaultPatternParser extends FaweParser<Pattern> {
|
public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||||
|
|
||||||
public DefaultPatternParser(WorldEdit worldEdit) {
|
public DefaultPatternParser(WorldEdit worldEdit) {
|
||||||
super(worldEdit);
|
super(worldEdit, "patterns");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,7 +73,7 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
|
|||||||
List<String> args = entry.getValue();
|
List<String> args = entry.getValue();
|
||||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||||
try {
|
try {
|
||||||
pattern = parse(cmdArgs, actor);
|
pattern = parse(command + cmdArgs, context);
|
||||||
} catch (SuggestInputParseException rethrow) {
|
} catch (SuggestInputParseException rethrow) {
|
||||||
throw rethrow;
|
throw rethrow;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -24,6 +24,7 @@ import com.sk89q.worldedit.extension.factory.MaskFactory;
|
|||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ public class ParserContext {
|
|||||||
private boolean restricted = true;
|
private boolean restricted = true;
|
||||||
private boolean tryLegacy = true;
|
private boolean tryLegacy = true;
|
||||||
private boolean preferringWildcard;
|
private boolean preferringWildcard;
|
||||||
|
private InjectedValueAccess injected;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
@ -248,4 +250,12 @@ public class ParserContext {
|
|||||||
public boolean isTryingLegacy() {
|
public boolean isTryingLegacy() {
|
||||||
return tryLegacy;
|
return tryLegacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInjected(InjectedValueAccess injected) {
|
||||||
|
this.injected = injected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InjectedValueAccess getInjected() {
|
||||||
|
return injected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -609,10 +609,17 @@ public final class PlatformCommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> T parse(String args, Actor actor) {
|
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) {
|
public <T> T parse(String args, InjectedValueAccess access) {
|
||||||
|
if (args.isEmpty()) return null;
|
||||||
String[] split = parseArgs(args)
|
String[] split = parseArgs(args)
|
||||||
.map(Substring::getSubstring)
|
.map(Substring::getSubstring)
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren