use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.
the class NPCCommandHandler method constants.
// <--[language]
// @name /npc constant command
// @group Console Commands
// @description
// The /npc constants command configures a NPC's constants. Uses Denizen's ConstantTrait to keep track of
// NPC-specific constants. This provides seamless integration with an assignment script's 'Default Constants' in
// which string variables can be stored and retrieved with the use of 'replaceable tags', or API. Constants set at
// the NPC level override any constants from the NPC's assignment script.
//
// Constants may be used in several ways: Setting, Removing, and Viewing
//
// To set a constant, all that is required is a name and value. Use the Bukkit command in the
// following manner: (Note the use of quotes on multi world values)
// /npc constant --set constant_name --value 'multi word value'
//
// Removing a constant from an NPC only requires a name. Note: It is not possible to remove a
// constant set by the NPCs Assignment Script, except by modifying the script itself.
// /npc constant --remove constant_name
//
// Viewing constants is easy, just use '/npc constant #', specifying a page number. Constants which
// have been overridden by the NPC are formatted with a strike-through to indicate this case.
//
// To reference a constant value, use the replaceable tag to get the NPCs 'constant' attribute. For example:
// <npc.constant[constant_name]>. Constants may also have other tags in their value, which will be replaced
// whenever the constant is used, allowing the use of dynamic information.
// -->
@Command(aliases = { "npc" }, usage = "constant --set|remove name --value constant value", desc = "Views/adds/removes NPC string constants.", flags = "r", modifiers = { "constants", "constant", "cons" }, min = 1, max = 3, permission = "denizen.npc.constants")
@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());
}
}
use of net.citizensnpcs.api.command.Command in project Denizen-For-Bukkit by DenizenScript.
the class NPCCommandHandler method trigger.
/*
* TRIGGER
*/
@Command(aliases = { "npc" }, usage = "trigger [trigger name] [(--cooldown [seconds])|(--radius [radius])|(-t)]", desc = "Controls the various triggers for an NPC.", flags = "t", modifiers = { "trigger", "tr" }, min = 1, max = 3, permission = "denizen.npc.trigger")
@Requirements(selected = true, ownership = true)
public void trigger(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.hasTrait(TriggerTrait.class)) {
npc.addTrait(TriggerTrait.class);
}
TriggerTrait trait = npc.getTrait(TriggerTrait.class);
if ((args.hasValueFlag("name") || (args.argsLength() > 1 && (args.getJoinedStrings(1) != null) && !args.getString(1).matches("\\d+")))) {
// Get the name of the trigger
String triggerName;
if (args.hasValueFlag("name")) {
triggerName = args.getFlag("name");
} else {
triggerName = args.getJoinedStrings(1);
}
// Check to make sure trigger exists
if (DenizenAPI.getCurrentInstance().getTriggerRegistry().get(triggerName) == null) {
Messaging.sendError(sender, "'" + triggerName.toUpperCase() + "' trigger does not exist.");
Messaging.send(sender, "<f>Usage: /npc trigger [trigger_name] [(--cooldown #)|(--radius #)|(-t)]");
Messaging.send(sender, "");
Messaging.send(sender, "<f>Use '--name trigger_name' to specify a specific trigger, and '-t' to toggle.");
Messaging.send(sender, "<b>Example: /npc trigger --name damage -t");
Messaging.send(sender, "<f>You may also use '--cooldown #' to specify a new cooldown time, and '--radius #' to specify a specific radius, when applicable.");
Messaging.send(sender, "");
return;
}
// If toggling
if (args.hasFlag('t')) {
trait.toggleTrigger(triggerName);
}
// If setting cooldown
if (args.hasValueFlag("cooldown")) {
trait.setLocalCooldown(triggerName, args.getFlagDouble("cooldown"));
}
// If specifying radius
if (args.hasValueFlag("radius")) {
trait.setLocalRadius(triggerName, args.getFlagInteger("radius"));
Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger radius now " + args.getFlag("radius") + ".");
}
// Show current status of the trigger
Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger " + (trait.isEnabled(triggerName) ? "is" : "is not") + " currently enabled" + (trait.isEnabled(triggerName) ? " with a cooldown of '" + trait.getCooldownDuration(triggerName) + "' seconds." : "."));
return;
}
try {
trait.describe(sender, args.getInteger(1, 1));
} catch (net.citizensnpcs.api.command.exception.CommandException e) {
throw new CommandException(e.getMessage());
}
}
use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method shulker.
@Command(aliases = { "npc" }, usage = "shulker (--peek [peek] --color [color])", desc = "Sets shulker modifiers.", modifiers = { "shulker" }, min = 1, max = 1, permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
trait.setPeek(peek);
Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek);
hasArg = true;
}
if (args.hasValueFlag("color")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
if (color == null) {
Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values()));
return;
}
trait.setColor(color);
Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color));
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method parrot.
@Command(aliases = { "npc" }, usage = "parrot (--variant variant)", desc = "Sets parrot modifiers", modifiers = { "parrot" }, min = 1, max = 1, permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ParrotTrait trait = npc.getTrait(ParrotTrait.class);
String output = "";
if (args.hasValueFlag("variant")) {
String variantRaw = args.getFlag("variant");
Variant variant = Util.matchEnum(Variant.values(), variantRaw);
if (variant == null) {
String valid = Util.listValuesPretty(Variant.values());
throw new CommandException(Messages.INVALID_PARROT_VARIANT, valid);
}
trait.setVariant(variant);
output += Messaging.tr(Messages.PARROT_VARIANT_SET, Util.prettyEnum(variant));
}
if (!output.isEmpty()) {
Messaging.send(sender, output);
}
}
use of net.citizensnpcs.api.command.Command in project Citizens2 by CitizensDev.
the class Commands method shulker.
@Command(aliases = { "npc" }, usage = "shulker (--peek [peek] --color [color])", desc = "Sets shulker modifiers.", modifiers = { "shulker" }, min = 1, max = 1, permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
trait.setPeek(peek);
Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek);
hasArg = true;
}
if (args.hasValueFlag("color")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
if (color == null) {
Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values()));
return;
}
trait.setColor(color);
Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color));
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
Aggregations