@Requirements(selected = true, ownership = true)
public void constants(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.hasTrait(ConstantsTrait.class)) npc.addTrait(ConstantsTrait.class);
ConstantsTrait trait = npc.getTrait(ConstantsTrait.class);
if (args.hasValueFlag("set")) {
if (!args.hasValueFlag("value")) throw new CommandException("--SET requires use of the '--VALUE \"constant value\"' argument.");
trait.setConstant(args.getFlag("set"), args.getFlag("value"));
Messaging.sendInfo(sender, npc.getName() + " has added constant '" + args.getFlag("set") + "'.");
return;
} else if (args.hasValueFlag("remove")) {
trait.removeConstant(args.getFlag("remove"));
Messaging.sendInfo(sender, npc.getName() + " has removed constant '" + args.getFlag("remove") + "'.");
return;
} else if (args.length() > 2 && args.getInteger(1, 0) < 1) {
Messaging.send(sender, "");
Messaging.send(sender, "<f>Use '--set name' to add/set a new NPC-specific constant.");
Messaging.send(sender, "<f>Must also specify '--value \"constant value\"'.");
Messaging.send(sender, "<b>Example: /npc constant --set constant_1 --value \"test value\"");
Messaging.send(sender, "<f>Remove NPC-specific constants with '--remove name'");
Messaging.send(sender, "<f>Note: Constants set will override any specified in an");
Messaging.send(sender, "<f>assignment. Constants specified in assignments cannot be");
Messaging.send(sender, "<f>removed with this command.");
Messaging.send(sender, "");
return;
}
try {
trait.describe(sender, args.getInteger(1, 1));
} catch (net.citizensnpcs.api.command.exception.CommandException e) {
throw new CommandException(e.getMessage());
}
}