Search in sources :

Example 46 with CommandException

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));
}
Also used : Waypoints(net.citizensnpcs.trait.waypoint.Waypoints) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

Example 47 with CommandException

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);
    }
}
Also used : CommandException(net.citizensnpcs.api.command.exception.CommandException) NPCLoadException(net.citizensnpcs.api.exception.NPCLoadException) Command(net.citizensnpcs.api.command.Command)

Example 48 with CommandException

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);
    }
}
Also used : BarColor(org.bukkit.boss.BarColor) Color(org.bukkit.entity.Llama.Color) DyeColor(org.bukkit.DyeColor) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 49 with CommandException

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());
    }
}
Also used : CommandException(net.citizensnpcs.api.command.exception.CommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Aggregations

CommandException (net.citizensnpcs.api.command.exception.CommandException)49 Command (net.citizensnpcs.api.command.Command)40 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)30 Requirements (net.citizensnpcs.api.command.Requirements)25 NPC (net.citizensnpcs.api.npc.NPC)9 Player (org.bukkit.entity.Player)8 Paginator (net.citizensnpcs.api.util.Paginator)7 Location (org.bukkit.Location)7 CurrentLocation (net.citizensnpcs.trait.CurrentLocation)6 DyeColor (org.bukkit.DyeColor)5 NoPermissionsException (net.citizensnpcs.api.command.exception.NoPermissionsException)4 Owner (net.citizensnpcs.api.trait.trait.Owner)4 UnhandledCommandException (net.citizensnpcs.api.command.exception.UnhandledCommandException)3 WrappedCommandException (net.citizensnpcs.api.command.exception.WrappedCommandException)3 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)3 CommandUsageException (net.citizensnpcs.api.command.exception.CommandUsageException)2 CommandSenderCreateNPCEvent (net.citizensnpcs.api.event.CommandSenderCreateNPCEvent)2 PlayerCreateNPCEvent (net.citizensnpcs.api.event.PlayerCreateNPCEvent)2 Template (net.citizensnpcs.npc.Template)2 Age (net.citizensnpcs.trait.Age)2