Fixed handling of legacy Command.flags/.anyFlags.

Fixes WORLDEDIT-3137.
This commit is contained in:
sk89q 2014-07-01 14:15:19 -07:00
parent 7ba002ac8d
commit ede28df487

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util.command.parametric; 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.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
@ -55,6 +56,8 @@ class ParametricCallable implements CommandCallable {
private final Method method; private final Method method;
private final ParameterData[] parameters; private final ParameterData[] parameters;
private final Set<Character> valueFlags = new HashSet<Character>(); private final Set<Character> valueFlags = new HashSet<Character>();
private final boolean anyFlags;
private final Set<Character> legacyFlags = new HashSet<Character>();
private final SimpleDescription description = new SimpleDescription(); private final SimpleDescription description = new SimpleDescription();
private final CommandPermissions commandPermissions; 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 // Finish description
description.setDescription(!definition.desc().isEmpty() ? definition.desc() : null); description.setDescription(!definition.desc().isEmpty() ? definition.desc() : null);
description.setHelp(!definition.help().isEmpty() ? definition.help() : null); description.setHelp(!definition.help().isEmpty() ? definition.help() : null);
@ -412,35 +419,41 @@ class ParametricCallable implements CommandCallable {
* @param context the command context * @param context the command context
*/ */
private String getUnusedFlags(CommandContext context) { private String getUnusedFlags(CommandContext context) {
Set<Character> unusedFlags = null; if (!anyFlags) {
for (char flag : context.getFlags()) { Set<Character> unusedFlags = null;
boolean found = false; for (char flag : context.getFlags()) {
boolean found = false;
for (ParameterData parameter : parameters) { if (legacyFlags.contains(flag)) {
Character paramFlag = parameter.getFlag();
if (paramFlag != null && flag == paramFlag) {
found = true;
break; break;
} }
}
for (ParameterData parameter : parameters) {
if (!found) { Character paramFlag = parameter.getFlag();
if (unusedFlags == null) { if (paramFlag != null && flag == paramFlag) {
unusedFlags = new HashSet<Character>(); found = true;
break;
}
} }
unusedFlags.add(flag);
if (!found) {
if (unusedFlags == null) {
unusedFlags = new HashSet<Character>();
}
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; return null;
} }