use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.
the class WaypointCommands method provider.
@Command(aliases = { "waypoints", "waypoint", "wp" }, usage = "provider [provider name] (-d)", desc = "Sets the current waypoint provider", modifiers = { "provider" }, min = 1, max = 2, flags = "d", permission = "citizens.waypoints.provider")
public void provider(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Waypoints waypoints = npc.getTrait(Waypoints.class);
if (args.argsLength() == 1) {
if (args.hasFlag('d')) {
waypoints.describeProviders(sender);
} else {
Messaging.sendTr(sender, Messages.CURRENT_WAYPOINT_PROVIDER, waypoints.getCurrentProviderName());
}
return;
}
boolean success = waypoints.setWaypointProvider(args.getString(1));
if (!success)
throw new CommandException("Provider not found.");
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, args.getString(1));
}
use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.
the class AdminCommands method reload.
@Command(aliases = { "citizens" }, usage = "reload", desc = "Reload Citizens", modifiers = { "reload" }, min = 1, max = 1, permission = "citizens.admin")
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Messaging.sendTr(sender, Messages.CITIZENS_RELOADING);
try {
plugin.reload();
Messaging.sendTr(sender, Messages.CITIZENS_RELOADED);
} catch (NPCLoadException ex) {
ex.printStackTrace();
throw new CommandException(Messages.CITIZENS_RELOAD_ERROR);
}
}
use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.
the class Commands method llama.
@Command(aliases = { "npc" }, usage = "llama (--color color) (--strength strength)", desc = "Sets llama modifiers", modifiers = { "llama" }, min = 1, max = 1, permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
Color color = Util.matchEnum(Color.values(), colorRaw);
if (color == null) {
String valid = Util.listValuesPretty(Color.values());
throw new CommandException(Messages.INVALID_LLAMA_COLOR, valid);
}
trait.setColor(color);
output += Messaging.tr(Messages.LLAMA_COLOR_SET, Util.prettyEnum(color));
}
if (args.hasValueFlag("strength")) {
trait.setStrength(Math.max(1, Math.min(5, args.getFlagInteger("strength"))));
output += Messaging.tr(Messages.LLAMA_STRENGTH_SET, args.getFlagInteger("strength"));
}
if (!output.isEmpty()) {
Messaging.send(sender, output);
}
}
use of net.citizensnpcs.api.command.exception.CommandException in project Denizen-For-Bukkit by DenizenScript.
the class NPCCommandHandler method 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 {
TriggerTrait trait = npc.getOrAddTrait(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 (Denizen.getInstance().triggerRegistry.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());
}
}
Aggregations