Search in sources :

Example 1 with WolfModifiers

use of net.citizensnpcs.trait.WolfModifiers in project Citizens2 by CitizensDev.

the class NPCCommands method wolf.

@Command(aliases = { "npc" }, usage = "wolf (-s(itting) a(ngry) t(amed) i(nfo)) --collar [hex rgb color|name]", desc = "Sets wolf modifiers", modifiers = { "wolf" }, min = 1, max = 1, requiresFlags = true, flags = "sati", permission = "citizens.npc.wolf")
@Requirements(selected = true, ownership = true, types = EntityType.WOLF)
public void wolf(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    WolfModifiers trait = npc.getTrait(WolfModifiers.class);
    if (args.hasFlag('a')) {
        trait.setAngry(!trait.isAngry());
    }
    if (args.hasFlag('s')) {
        trait.setSitting(!trait.isSitting());
    }
    if (args.hasFlag('t')) {
        trait.setTamed(!trait.isTamed());
    }
    if (args.hasValueFlag("collar")) {
        String unparsed = args.getFlag("collar");
        DyeColor color = null;
        try {
            color = DyeColor.valueOf(unparsed.toUpperCase().replace(' ', '_'));
        } catch (IllegalArgumentException e) {
            try {
                int rgb = Integer.parseInt(unparsed.replace("#", ""), 16);
                color = DyeColor.getByColor(org.bukkit.Color.fromRGB(rgb));
            } catch (NumberFormatException ex) {
                throw new CommandException(Messages.COLLAR_COLOUR_NOT_RECOGNISED, unparsed);
            }
        }
        if (color == null)
            throw new CommandException(Messages.COLLAR_COLOUR_NOT_SUPPORTED, unparsed);
        trait.setCollarColor(color);
    }
    Messaging.sendTr(sender, Messages.WOLF_TRAIT_UPDATED, npc.getName(), trait.isAngry(), trait.isSitting(), trait.isTamed(), trait.getCollarColor().name());
}
Also used : WolfModifiers(net.citizensnpcs.trait.WolfModifiers) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) DyeColor(org.bukkit.DyeColor) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Aggregations

Command (net.citizensnpcs.api.command.Command)1 Requirements (net.citizensnpcs.api.command.Requirements)1 CommandException (net.citizensnpcs.api.command.exception.CommandException)1 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)1 WolfModifiers (net.citizensnpcs.trait.WolfModifiers)1 DyeColor (org.bukkit.DyeColor)1