mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Use literal as the default argument when generating a syntax
This commit is contained in:
parent
502ec22b92
commit
8f3ee93191
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user