Search in sources :

Example 11 with CommandException

use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.

the class NPCCommands method age.

@Command(aliases = { "npc" }, usage = "age [age] (-l)", desc = "Set the age of a NPC", help = Messages.COMMAND_AGE_HELP, flags = "l", modifiers = { "age" }, min = 1, max = 2, permission = "citizens.npc.age")
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    if (!npc.isSpawned() || (!(npc.getEntity() instanceof Ageable) && !(npc.getEntity() instanceof Zombie)))
        throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED, npc.getName());
    Age trait = npc.getTrait(Age.class);
    boolean toggleLock = args.hasFlag('l');
    if (toggleLock) {
        Messaging.sendTr(sender, trait.toggle() ? Messages.AGE_LOCKED : Messages.AGE_UNLOCKED);
    }
    if (args.argsLength() <= 1) {
        if (!toggleLock)
            trait.describe(sender);
        return;
    }
    int age = 0;
    try {
        age = args.getInteger(1);
        if (age > 0) {
            throw new CommandException(Messages.INVALID_AGE);
        }
        Messaging.sendTr(sender, Messages.AGE_SET_NORMAL, npc.getName(), age);
    } catch (NumberFormatException ex) {
        if (args.getString(1).equalsIgnoreCase("baby")) {
            age = -24000;
            Messaging.sendTr(sender, Messages.AGE_SET_BABY, npc.getName());
        } else if (args.getString(1).equalsIgnoreCase("adult")) {
            age = 0;
            Messaging.sendTr(sender, Messages.AGE_SET_ADULT, npc.getName());
        } else
            throw new CommandException(Messages.INVALID_AGE);
    }
    trait.setAge(age);
}
Also used : Zombie(org.bukkit.entity.Zombie) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Ageable(org.bukkit.entity.Ageable) Age(net.citizensnpcs.trait.Age) Command(net.citizensnpcs.api.command.Command)

Example 12 with CommandException

use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.

the class NPCCommands method type.

@Command(aliases = { "npc" }, usage = "type [type]", desc = "Sets an NPC's entity type", modifiers = { "type" }, min = 2, max = 2, permission = "citizens.npc.type")
public void type(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    EntityType type = Util.matchEntityType(args.getString(1));
    if (type == null)
        throw new CommandException(Messages.INVALID_ENTITY_TYPE, args.getString(1));
    npc.setBukkitEntityType(type);
    Messaging.sendTr(sender, Messages.ENTITY_TYPE_SET, npc.getName(), args.getString(1));
}
Also used : EntityType(org.bukkit.entity.EntityType) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

Example 13 with CommandException

use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.

the class NPCCommands method speed.

@Command(aliases = { "npc" }, usage = "speed [speed]", desc = "Sets the movement speed of an NPC as a percentage", modifiers = { "speed" }, min = 2, max = 2, permission = "citizens.npc.speed")
public void speed(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    float newSpeed = (float) Math.abs(args.getDouble(1));
    if (newSpeed >= Setting.MAX_SPEED.asDouble())
        throw new CommandException(Messages.SPEED_MODIFIER_ABOVE_LIMIT);
    npc.getNavigator().getDefaultParameters().speedModifier(newSpeed);
    Messaging.sendTr(sender, Messages.SPEED_MODIFIER_SET, newSpeed);
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command)

Example 14 with CommandException

use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.

the class NPCCommands method horse.

@Command(aliases = { "npc" }, usage = "horse (--color color) (--type type) (--style style) (-cb)", desc = "Sets horse modifiers", help = "Use the -c flag to make the horse have a chest, or the -b flag to stop them from having a chest.", modifiers = { "horse" }, min = 1, max = 1, flags = "cb", permission = "citizens.npc.horse")
@Requirements(selected = true, ownership = true, types = EntityType.HORSE)
public void horse(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    HorseModifiers horse = npc.getTrait(HorseModifiers.class);
    String output = "";
    if (args.hasFlag('c')) {
        horse.setCarryingChest(true);
        output += Messaging.tr(Messages.HORSE_CHEST_SET) + " ";
    } else if (args.hasFlag('b')) {
        horse.setCarryingChest(false);
        output += Messaging.tr(Messages.HORSE_CHEST_UNSET) + " ";
    }
    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_HORSE_COLOR, valid);
        }
        horse.setColor(color);
        output += Messaging.tr(Messages.HORSE_COLOR_SET, Util.prettyEnum(color));
    }
    if (args.hasValueFlag("style")) {
        Style style = Util.matchEnum(Style.values(), args.getFlag("style"));
        if (style == null) {
            String valid = Util.listValuesPretty(Style.values());
            throw new CommandException(Messages.INVALID_HORSE_STYLE, valid);
        }
        horse.setStyle(style);
        output += Messaging.tr(Messages.HORSE_STYLE_SET, Util.prettyEnum(style));
    }
    if (output.isEmpty()) {
        Messaging.sendTr(sender, Messages.HORSE_DESCRIBE, Util.prettyEnum(horse.getColor()), Util.prettyEnum(horse.getNPC().getEntity().getType()), Util.prettyEnum(horse.getStyle()));
    } else {
        sender.sendMessage(output);
    }
}
Also used : Color(org.bukkit.entity.Horse.Color) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) Style(org.bukkit.entity.Horse.Style) HorseModifiers(net.citizensnpcs.trait.HorseModifiers) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 15 with CommandException

use of net.citizensnpcs.api.command.exception.CommandException in project Citizens2 by CitizensDev.

the class NPCCommands method metadata.

@Command(aliases = { "npc" }, usage = "metadata set|get|remove [key] (value) (-t(emporary))", desc = "Manages NPC metadata", modifiers = { "metadata" }, flags = "t", min = 2, max = 4, permission = "citizens.npc.metadata")
@Requirements(selected = true, ownership = true)
public void metadata(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String command = args.getString(1).toLowerCase();
    if (command.equals("set")) {
        if (args.argsLength() != 4)
            throw new CommandException();
        if (args.hasFlag('t')) {
            npc.data().set(args.getString(2), args.getString(3));
        } else {
            npc.data().setPersistent(args.getString(2), args.getString(3));
        }
        Messaging.sendTr(sender, Messages.METADATA_SET, args.getString(2), args.getString(3));
    } else if (args.equals("get")) {
        if (args.argsLength() != 3) {
            throw new CommandException();
        }
        Messaging.send(sender, npc.data().get(args.getString(2), "null"));
    } else if (args.equals("remove")) {
        if (args.argsLength() != 3) {
            throw new CommandException();
        }
        npc.data().remove(args.getString(3));
        Messaging.sendTr(sender, Messages.METADATA_UNSET, args.getString(2));
    }
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) 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