3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-09 21:10:05 +01:00

Fixed handling of legacy Command.flags/.anyFlags.

Fixes WORLDEDIT-3137.
Dieser Commit ist enthalten in:
sk89q 2014-07-01 14:15:19 -07:00
Ursprung 7ba002ac8d
Commit ede28df487

Datei anzeigen

@ -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,10 +419,15 @@ class ParametricCallable implements CommandCallable {
* @param context the command context * @param context the command context
*/ */
private String getUnusedFlags(CommandContext context) { private String getUnusedFlags(CommandContext context) {
if (!anyFlags) {
Set<Character> unusedFlags = null; Set<Character> unusedFlags = null;
for (char flag : context.getFlags()) { for (char flag : context.getFlags()) {
boolean found = false; boolean found = false;
if (legacyFlags.contains(flag)) {
break;
}
for (ParameterData parameter : parameters) { for (ParameterData parameter : parameters) {
Character paramFlag = parameter.getFlag(); Character paramFlag = parameter.getFlag();
if (paramFlag != null && flag == paramFlag) { if (paramFlag != null && flag == paramFlag) {
@ -440,6 +452,7 @@ class ParametricCallable implements CommandCallable {
return builder.toString().trim(); return builder.toString().trim();
} }
}
return null; return null;
} }