ArgumentWord restrictions should be part of the correction instead of the condition

This commit is contained in:
themode 2021-01-05 21:54:17 +01:00
parent 9546caca04
commit 2634105ad1
2 changed files with 11 additions and 10 deletions

View File

@ -107,6 +107,7 @@ public class CommandDispatcher {
return commandMap.getOrDefault(commandName, null);
}
@NotNull
private CommandResult findCommandResult(@NotNull Command command, @NotNull String[] args) {
CommandResult result = new CommandResult();
result.command = command;

View File

@ -29,7 +29,7 @@ public class ArgumentWord extends Argument<String> {
* WARNING: having an array too long would result in a packet too big or the client being stuck during login.
*
* @param restrictions the accepted words
* @return 'this'
* @return 'this' for chaining
*/
@NotNull
public ArgumentWord from(@Nullable String... restrictions) {
@ -42,6 +42,15 @@ public class ArgumentWord extends Argument<String> {
if (value.contains(" "))
return SPACE_ERROR;
// Check restrictions (acting as literal)
if (hasRestrictions()) {
for (String r : restrictions) {
if (value.equalsIgnoreCase(r))
return SUCCESS;
}
return RESTRICTION_ERROR;
}
return SUCCESS;
}
@ -53,15 +62,6 @@ public class ArgumentWord extends Argument<String> {
@Override
public int getConditionResult(@NotNull String value) {
// Check restrictions
if (hasRestrictions()) {
for (String r : restrictions) {
if (value.equalsIgnoreCase(r))
return SUCCESS;
}
return RESTRICTION_ERROR;
}
return SUCCESS;
}