Search in sources :

Example 1 with HorseModifiers

use of net.citizensnpcs.trait.HorseModifiers 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)

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 HorseModifiers (net.citizensnpcs.trait.HorseModifiers)1 ChatColor (org.bukkit.ChatColor)1 DyeColor (org.bukkit.DyeColor)1 Color (org.bukkit.entity.Horse.Color)1 Style (org.bukkit.entity.Horse.Style)1