From ede28df487e82ec1f2d64fba3a239563ddb08301 Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 1 Jul 2014 14:15:19 -0700 Subject: [PATCH] Fixed handling of legacy Command.flags/.anyFlags. Fixes WORLDEDIT-3137. --- .../parametric/ParametricCallable.java | 59 +++++++++++-------- 1 file changed, 36 insertions(+), 23 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 eb4bc8d1a..cd59cbfb6 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.util.command.parametric; +import com.google.common.primitives.Chars; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; @@ -55,6 +56,8 @@ class ParametricCallable implements CommandCallable { private final Method method; private final ParameterData[] parameters; private final Set valueFlags = new HashSet(); + private final boolean anyFlags; + private final Set legacyFlags = new HashSet(); private final SimpleDescription description = new SimpleDescription(); private final CommandPermissions commandPermissions; @@ -157,6 +160,10 @@ class ParametricCallable implements CommandCallable { } } + // Gather legacy flags + anyFlags = definition.anyFlags(); + legacyFlags.addAll(Chars.asList(definition.flags().toCharArray())); + // Finish description description.setDescription(!definition.desc().isEmpty() ? definition.desc() : null); description.setHelp(!definition.help().isEmpty() ? definition.help() : null); @@ -412,35 +419,41 @@ class ParametricCallable implements CommandCallable { * @param context the command context */ private String getUnusedFlags(CommandContext context) { - Set unusedFlags = null; - for (char flag : context.getFlags()) { - boolean found = false; + if (!anyFlags) { + Set unusedFlags = null; + for (char flag : context.getFlags()) { + boolean found = false; - for (ParameterData parameter : parameters) { - Character paramFlag = parameter.getFlag(); - if (paramFlag != null && flag == paramFlag) { - found = true; + if (legacyFlags.contains(flag)) { break; } - } - - if (!found) { - if (unusedFlags == null) { - unusedFlags = new HashSet(); + + for (ParameterData parameter : parameters) { + Character paramFlag = parameter.getFlag(); + if (paramFlag != null && flag == paramFlag) { + found = true; + break; + } } - unusedFlags.add(flag); + + if (!found) { + if (unusedFlags == null) { + unusedFlags = new HashSet(); + } + unusedFlags.add(flag); + } + } + + if (unusedFlags != null) { + StringBuilder builder = new StringBuilder(); + for (Character flag : unusedFlags) { + builder.append("-").append(flag).append(" "); + } + + return builder.toString().trim(); } } - - if (unusedFlags != null) { - StringBuilder builder = new StringBuilder(); - for (Character flag : unusedFlags) { - builder.append("-").append(flag).append(" "); - } - - return builder.toString().trim(); - } - + return null; }