Search in sources :

Example 1 with SheepTrait

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

the class NPCCommands method sheep.

@Command(aliases = { "npc" }, usage = "sheep (--color [color]) (--sheared [sheared])", desc = "Sets sheep modifiers", modifiers = { "sheep" }, min = 1, max = 1, permission = "citizens.npc.sheep")
@Requirements(selected = true, ownership = true, types = { EntityType.SHEEP })
public void sheep(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    SheepTrait trait = npc.getTrait(SheepTrait.class);
    boolean hasArg = false;
    if (args.hasValueFlag("sheared")) {
        trait.setSheared(Boolean.valueOf(args.getFlag("sheared")));
        hasArg = true;
    }
    if (args.hasValueFlag("color")) {
        DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color"));
        if (color != null) {
            trait.setColor(color);
            Messaging.sendTr(sender, Messages.SHEEP_COLOR_SET, color.toString().toLowerCase());
        } else {
            Messaging.sendErrorTr(sender, Messages.INVALID_SHEEP_COLOR, Util.listValuesPretty(DyeColor.values()));
        }
        hasArg = true;
    }
    if (!hasArg) {
        throw new CommandException();
    }
}
Also used : ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) DyeColor(org.bukkit.DyeColor) SheepTrait(net.citizensnpcs.trait.SheepTrait) 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 SheepTrait (net.citizensnpcs.trait.SheepTrait)1 DyeColor (org.bukkit.DyeColor)1