Use literal as the default argument when generating a syntax

This commit is contained in:
TheMode 2021-04-16 21:51:33 +02:00
parent 502ec22b92
commit 8f3ee93191
2 changed files with 18 additions and 9 deletions

View File

@ -82,10 +82,14 @@ public class ArgumentParser {
// No state
if (state == 0) {
if (c == ' ')
continue;
if (c == '<') {
if (c == ' ') {
// Use literal as the default argument
final String argument = builder.toString();
if (argument.length() != 0) {
result.add(new ArgumentLiteral(argument));
builder = new StringBuilder();
}
} else if (c == '<') {
// Retrieve argument type
final String argument = builder.toString();
argumentFunction = ARGUMENT_FUNCTION_MAP.get(argument);
@ -122,6 +126,14 @@ public class ArgumentParser {
}
// Use remaining as literal if present
if (state == 0) {
final String argument = builder.toString();
if (argument.length() != 0) {
result.add(new ArgumentLiteral(argument));
}
}
return result.toArray(Argument[]::new);
}

View File

@ -4,8 +4,7 @@ import net.kyori.adventure.text.Component;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
import static net.minestom.server.command.builder.arguments.ArgumentType.ResourceLocation;
import net.minestom.server.command.builder.arguments.ArgumentType;
public class TestCommand extends Command {
@ -13,9 +12,7 @@ public class TestCommand extends Command {
super("testcmd");
setDefaultExecutor(this::usage);
var test = ResourceLocation("msg");
addSyntax((sender, context) -> System.out.println("executed"),test);
addSyntax((sender, context) -> System.out.println("executed"), ArgumentType.generate("test get"));
}
private void usage(CommandSender sender, CommandContext context) {