mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-12-01 18:36:49 +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) {
|
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--) {
|
args.removeIf(arg -> {
|
||||||
String arg = args.get(i).toLowerCase();
|
var argL = arg.toLowerCase();
|
||||||
boolean deleteArg = false;
|
boolean deleteArg = false;
|
||||||
int argNum;
|
|
||||||
for (var entry : map.entrySet()) {
|
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);
|
entry.getValue().accept(params, argNum);
|
||||||
deleteArg = true;
|
deleteArg = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (deleteArg) {
|
return deleteArg;
|
||||||
args.remove(i);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user