From c926fe326c01a4ea4f6ea3c8e53090f79c4ebeb6 Mon Sep 17 00:00:00 2001 From: AnimeGitB Date: Thu, 3 Nov 2022 01:13:16 +1030 Subject: [PATCH] Refactor command kwarg parsing --- .../emu/grasscutter/command/CommandHelpers.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/CommandHelpers.java b/src/main/java/emu/grasscutter/command/CommandHelpers.java index ff1ea386f..b5cf92972 100644 --- a/src/main/java/emu/grasscutter/command/CommandHelpers.java +++ b/src/main/java/emu/grasscutter/command/CommandHelpers.java @@ -33,21 +33,18 @@ public class CommandHelpers { } public static List parseIntParameters(List args, @Nonnull T params, Map> 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; } }