Commit c926fe32 authored by AnimeGitB's avatar AnimeGitB
Browse files

Refactor command kwarg parsing

parent e8930e92
...@@ -33,21 +33,18 @@ public class CommandHelpers { ...@@ -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) {
args.remove(i);
} }
} }
return deleteArg;
});
return args; return args;
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment