Changed how parsing is done, performed by dispatcher and can now look as deep as needed
This commit is contained in:
@@ -2,6 +2,7 @@ package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.arguments.CommandArgumentType;
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.context.ParsedArgument;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
@@ -25,23 +26,16 @@ public class ArgumentCommandNode<T> extends CommandNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
||||
public String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
||||
ParsedArgument<T> parsed = type.parse(command);
|
||||
int start = parsed.getRaw().length() + 1;
|
||||
int start = parsed.getRaw().length();
|
||||
|
||||
if (start < command.length()) {
|
||||
String result = command.substring(start);
|
||||
contextBuilder.withArgument(name, parsed);
|
||||
|
||||
for (CommandNode node : getChildren()) {
|
||||
try {
|
||||
return node.parse(result);
|
||||
} catch (IllegalArgumentSyntaxException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentSyntaxException();
|
||||
if (command.length() > start) {
|
||||
return command.substring(start + 1);
|
||||
} else {
|
||||
return this;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.minecraft.commands.tree;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
|
||||
@@ -27,5 +28,5 @@ public abstract class CommandNode {
|
||||
children.add(node);
|
||||
}
|
||||
|
||||
public abstract CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException;
|
||||
public abstract String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
|
||||
@@ -17,26 +18,16 @@ public class LiteralCommandNode extends CommandNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
||||
if (command.startsWith(literal)) {
|
||||
int start = literal.length() + 1;
|
||||
|
||||
if (start < command.length()) {
|
||||
String result = command.substring(start);
|
||||
|
||||
for (CommandNode node : getChildren()) {
|
||||
try {
|
||||
return node.parse(result);
|
||||
} catch (IllegalArgumentSyntaxException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentSyntaxException();
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
} else {
|
||||
public String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
||||
if (!command.startsWith(literal)) {
|
||||
throw new IllegalArgumentSyntaxException();
|
||||
}
|
||||
|
||||
int start = literal.length();
|
||||
if (command.length() > start) {
|
||||
return command.substring(start + 1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
|
||||
public class RootCommandNode extends CommandNode {
|
||||
public RootCommandNode() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user