mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 07:37:43 +00:00
Refactor command kwarg parsing
This commit is contained in:
parent
e8930e92e1
commit
c926fe326c
@ -33,21 +33,18 @@ public class CommandHelpers {
|
||||
}
|
||||
|
||||
public static <T> List<String> parseIntParameters(List<String> args, @Nonnull T params, Map<Pattern, BiConsumer<T, Integer>> map) {
|
||||
for (int i = args.size() - 1; i >= 0; i--) {
|
||||
String arg = args.get(i).toLowerCase();
|
||||
args.removeIf(arg -> {
|
||||
var argL = arg.toLowerCase();
|
||||
boolean deleteArg = false;
|
||||
int argNum;
|
||||
for (var entry : map.entrySet()) {
|
||||
if ((argNum = matchIntOrNeg(entry.getKey(), arg)) != -1) {
|
||||
int argNum = matchIntOrNeg(entry.getKey(), argL);
|
||||
if (argNum != -1) {
|
||||
entry.getValue().accept(params, argNum);
|
||||
deleteArg = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deleteArg) {
|
||||
args.remove(i);
|
||||
}
|
||||
}
|
||||
return deleteArg;
|
||||
});
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user