mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 00:17:58 +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
|
// No state
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
if (c == ' ')
|
if (c == ' ') {
|
||||||
continue;
|
// Use literal as the default argument
|
||||||
|
final String argument = builder.toString();
|
||||||
if (c == '<') {
|
if (argument.length() != 0) {
|
||||||
|
result.add(new ArgumentLiteral(argument));
|
||||||
|
builder = new StringBuilder();
|
||||||
|
}
|
||||||
|
} else if (c == '<') {
|
||||||
// Retrieve argument type
|
// Retrieve argument type
|
||||||
final String argument = builder.toString();
|
final String argument = builder.toString();
|
||||||
argumentFunction = ARGUMENT_FUNCTION_MAP.get(argument);
|
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);
|
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.CommandSender;
|
||||||
import net.minestom.server.command.builder.Command;
|
import net.minestom.server.command.builder.Command;
|
||||||
import net.minestom.server.command.builder.CommandContext;
|
import net.minestom.server.command.builder.CommandContext;
|
||||||
|
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||||
import static net.minestom.server.command.builder.arguments.ArgumentType.ResourceLocation;
|
|
||||||
|
|
||||||
public class TestCommand extends Command {
|
public class TestCommand extends Command {
|
||||||
|
|
||||||
@ -13,9 +12,7 @@ public class TestCommand extends Command {
|
|||||||
super("testcmd");
|
super("testcmd");
|
||||||
setDefaultExecutor(this::usage);
|
setDefaultExecutor(this::usage);
|
||||||
|
|
||||||
var test = ResourceLocation("msg");
|
addSyntax((sender, context) -> System.out.println("executed"), ArgumentType.generate("test get"));
|
||||||
|
|
||||||
addSyntax((sender, context) -> System.out.println("executed"),test);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void usage(CommandSender sender, CommandContext context) {
|
private void usage(CommandSender sender, CommandContext context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user