mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-27 02:21:38 +01:00
ArgumentWord restrictions should be part of the correction instead of the condition
This commit is contained in:
parent
9546caca04
commit
2634105ad1
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user