From 765d987ae14baaf8e1b95ac7ada4850a3d6b4ddb Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 2 Jul 2014 12:52:42 -0700 Subject: [PATCH] ParametricCallable.mayConsumeArguments() handles flags better. --- .../parametric/ParametricCallable.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index cd59cbfb6..a96434ac0 100644 --- a/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -344,20 +344,24 @@ class ParametricCallable implements CommandCallable { // Optional non-flag parameters: // - Before required parameters: Consume if there are 'left over' args // - At the end: Always consumes - - if (parameter.isOptional() && parameter.getFlag() == null) { - int numberFree = context.argsLength() - scoped.position(); - for (int j = i; j < parameters.length; j++) { - if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) { - // We already checked if the consumed count was > -1 - // when we created this object - numberFree -= parameters[j].getConsumedCount(); + + if (parameter.isOptional()) { + if (parameter.getFlag() != null) { + return !parameter.isValueFlag() || context.hasFlag(parameter.getFlag()); + } else { + int numberFree = context.argsLength() - scoped.position(); + for (int j = i; j < parameters.length; j++) { + if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) { + // We already checked if the consumed count was > -1 + // when we created this object + numberFree -= parameters[j].getConsumedCount(); + } + } + + // Skip this optional parameter + if (numberFree < 1) { + return false; } - } - - // Skip this optional parameter - if (numberFree < 1) { - return false; } }