Some javadocs, fix type coercion when checking for enabled

This commit is contained in:
fullwall 2013-01-10 22:40:46 +08:00
parent 1c59e2c30a
commit b3f151da09
4 changed files with 65 additions and 7 deletions

View File

@ -5,21 +5,59 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
/**
* A list of root-level command aliases that will be accepted for this
* command. For example: <code>{"npc", "npc2"}</code> would match both /npc
* and /npc2.
*/
String[] aliases();
/**
* A short description of the command that will be displayed with the
* command usage and help. Translatable.
*/
String desc();
/**
* Defines the flags available for this command. A flag is a single
* character such as <code>-f</code> that will alter the behaviour of the
* command. Each character in this string will be counted as a valid flag:
* extra flags will be discarded. Accepts * as a catch all.
*/
String flags() default "";
/**
* A longer description of the command and any flags it uses which will be
* displayed in addition to {@link desc} in help commands. Translatable.
*/
String help() default "";
/**
* The maximum number of arguments that the command will accept. Default is
* <code>-1</code>, or an <b>unlimited</b> number of arguments.
*/
int max() default -1;
/**
* Minimum number of arguments that are accepted by the command.
*/
int min() default 0;
/**
* The argument modifiers accepted by the command. Also accepts
* <code>'*'</code> as a catch all.
*/
String[] modifiers() default "";
/**
* The permission of the command. The comamnd sender will get an error if
* this is not met.
*/
String permission() default "";
/**
* Command usage string that is displayed when an error occurs with the
* command processing.
*/
String usage() default "";
}

View File

@ -7,8 +7,23 @@ import net.citizensnpcs.command.exception.CommandException;
import org.bukkit.command.CommandSender;
public interface CommandAnnotationProcessor {
/**
* @return The {@link Annotation} class that this processor will accept.
*/
Class<? extends Annotation> getAnnotationClass();
/**
* @param sender
* The command sender
* @param context
* The context of the command, including arguments
* @param instance
* The {@link Annotation} instance
* @param args
* The method arguments
* @throws CommandException
* If an exception occurs
*/
void process(CommandSender sender, CommandContext context, Annotation instance, Object[] args)
throws CommandException;
}

View File

@ -90,12 +90,12 @@ public class CommandManager {
// Attempt to execute a command.
private void executeMethod(String[] args, CommandSender sender, Object[] methodArgs) throws CommandException {
String cmdName = args[0];
String cmdName = args[0].toLowerCase();
String modifier = args.length > 1 ? args[1] : "";
Method method = commands.get(cmdName.toLowerCase() + " " + modifier.toLowerCase());
Method method = commands.get(cmdName + " " + modifier.toLowerCase());
if (method == null)
method = commands.get(cmdName.toLowerCase() + " *");
method = commands.get(cmdName + " *");
if (method == null)
throw new UnhandledCommandException();
@ -274,8 +274,8 @@ public class CommandManager {
* @return Whether the command is handled
*/
public boolean hasCommand(org.bukkit.command.Command cmd, String modifier) {
return commands.containsKey(cmd.getName().toLowerCase() + " " + modifier.toLowerCase())
|| commands.containsKey(cmd.getName().toLowerCase() + " *");
String cmdName = cmd.getName().toLowerCase();
return commands.containsKey(cmdName + " " + modifier.toLowerCase()) || commands.containsKey(cmdName + " *");
}
// Returns whether a CommandSenders has permission.

View File

@ -107,8 +107,12 @@ public class CitizensNPC extends AbstractNPC {
}
});
for (DataKey traitKey : keys) {
if (traitKey.keyExists("enabled") && !traitKey.getBoolean("enabled"))
if (traitKey.keyExists("enabled") && !traitKey.getBoolean("enabled")
&& traitKey.getRaw("enabled") instanceof Boolean) {
// we want to avoid coercion here as YAML can coerce map
// existence to boolean
continue;
}
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitKey.name());
Trait trait;
if (hasTrait(clazz)) {
@ -173,7 +177,8 @@ public class CitizensNPC extends AbstractNPC {
}
if (traitNames.length() > 0) {
root.setString("traitnames", traitNames.substring(0, traitNames.length() - 1));
}
} else
root.setString("traitnames", "");
removeTraitData(root);
}