mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Fix parsing for injected command types
This commit is contained in:
parent
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.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 {
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user