diff --git a/bluecommands-core/src/main/java/de/bluecolored/bluecommands/ArgumentCommand.java b/bluecommands-core/src/main/java/de/bluecolored/bluecommands/ArgumentCommand.java index 6f8bdcb..dc4bc12 100644 --- a/bluecommands-core/src/main/java/de/bluecolored/bluecommands/ArgumentCommand.java +++ b/bluecommands-core/src/main/java/de/bluecolored/bluecommands/ArgumentCommand.java @@ -26,6 +26,9 @@ import de.bluecolored.bluecommands.parsers.ArgumentParser; +import java.util.Collection; +import java.util.List; + public class ArgumentCommand extends Command { private final String argumentId; @@ -74,6 +77,21 @@ void parse(ParseData data) { throw new CommandSetupException("The ArgumentParser '" + argumentParser + "' did not consume the full token. (expected next char to be a space or end of string)"); } + // if we reached the end of input, check if there is any additional suggestions and add an extra failure if there are any + if (next == -1) { + input.setPosition(position); // reset position for suggestions + List extraSuggesions = argumentParser.suggest(context, input); + if (!extraSuggesions.isEmpty()) { + data.getResult().addFailure(new ParseFailure<>( + position, + "Alternative Usages", + data.getCommandStack(), + extraSuggesions + )); + } + input.readRemaining(); // reset position + } + data.getCurrentSegment().setValue(argument); super.parse(data); } catch (CommandParseException ex) { diff --git a/bluecommands-core/src/main/java/de/bluecolored/bluecommands/Command.java b/bluecommands-core/src/main/java/de/bluecolored/bluecommands/Command.java index 461497f..3b0695e 100644 --- a/bluecommands-core/src/main/java/de/bluecolored/bluecommands/Command.java +++ b/bluecommands-core/src/main/java/de/bluecolored/bluecommands/Command.java @@ -81,7 +81,7 @@ void parse(ParseData data) { data.popSegment(); } } - } else { + } else if (!subCommands.isEmpty()) { data.getResult().addFailure(new ParseFailure<>(inputPosition, "Not enough arguments!", data.getCommandStack())); } }