Search in sources :

Example 1 with Style

use of org.bukkit.entity.Horse.Style 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 2 with Style

use of org.bukkit.entity.Horse.Style in project MagicPlugin by elBukkit.

the class AlterSpell method alterEntity.

protected SpellResult alterEntity(Entity entity) {
    EntityType entityType = entity.getType();
    switch(entityType) {
        case PAINTING:
            registerModified(entity);
            Painting painting = (Painting) entity;
            Art[] artValues = Art.values();
            Art oldArt = painting.getArt();
            Art newArt = oldArt;
            int ordinal = (oldArt.ordinal() + 1);
            for (int i = 0; i < artValues.length; i++) {
                newArt = artValues[ordinal++ % artValues.length];
                painting.setArt(newArt);
                newArt = painting.getArt();
                if (oldArt != newArt) {
                    break;
                }
            }
            if (oldArt == newArt) {
                return SpellResult.FAIL;
            }
            mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
            break;
        case ITEM_FRAME:
            ItemFrame itemFrame = (ItemFrame) entity;
            ItemStack frameItem = itemFrame.getItem();
            if (frameItem == null || frameItem.getType() != Material.MAP) {
                return SpellResult.NO_TARGET;
            }
            short data = frameItem.getDurability();
            data++;
            MapView mapView = DeprecatedUtils.getMap(data);
            if (mapView == null) {
                data = 0;
                mapView = DeprecatedUtils.getMap(data);
                if (mapView == null) {
                    return SpellResult.NO_TARGET;
                }
            }
            registerModified(entity);
            frameItem.setDurability(data);
            itemFrame.setItem(frameItem);
            break;
        case HORSE:
            registerModified(entity);
            Horse horse = (Horse) entity;
            Color color = horse.getColor();
            Color[] colorValues = Color.values();
            color = colorValues[(color.ordinal() + 1) % colorValues.length];
            Style horseStyle = horse.getStyle();
            Style[] styleValues = Style.values();
            horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
            horse.setStyle(horseStyle);
            horse.setColor(color);
            break;
        case OCELOT:
            registerModified(entity);
            Ocelot ocelot = (Ocelot) entity;
            Type catType = ocelot.getCatType();
            Type[] typeValues = Type.values();
            catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
            ocelot.setCatType(catType);
            break;
        case VILLAGER:
            registerModified(entity);
            Villager villager = (Villager) entity;
            Profession profession = villager.getProfession();
            Profession[] professionValues = Profession.values();
            profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
            villager.setProfession(profession);
            break;
        case WOLF:
            registerModified(entity);
            Wolf wolf = (Wolf) entity;
            DyeColor wolfColor = wolf.getCollarColor();
            DyeColor[] wolfColorValues = DyeColor.values();
            wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
            wolf.setCollarColor(wolfColor);
            break;
        case SHEEP:
            registerModified(entity);
            Sheep sheep = (Sheep) entity;
            DyeColor dyeColor = sheep.getColor();
            DyeColor[] dyeColorValues = DyeColor.values();
            dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
            sheep.setColor(dyeColor);
            break;
        case SKELETON:
            registerModified(entity);
            Skeleton skeleton = (Skeleton) entity;
            SkeletonType skeletonType = skeleton.getSkeletonType();
            SkeletonType[] skeletonTypeValues = SkeletonType.values();
            skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
            skeleton.setSkeletonType(skeletonType);
            break;
        default:
            return SpellResult.NO_TARGET;
    }
    ;
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Art(org.bukkit.Art) ItemFrame(org.bukkit.entity.ItemFrame) SkeletonType(org.bukkit.entity.Skeleton.SkeletonType) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) MapView(org.bukkit.map.MapView) Style(org.bukkit.entity.Horse.Style) Skeleton(org.bukkit.entity.Skeleton) Wolf(org.bukkit.entity.Wolf) Color(org.bukkit.entity.Horse.Color) DyeColor(org.bukkit.DyeColor) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) EntityType(org.bukkit.entity.EntityType) Ocelot(org.bukkit.entity.Ocelot) SkeletonType(org.bukkit.entity.Skeleton.SkeletonType) Type(org.bukkit.entity.Ocelot.Type) EntityType(org.bukkit.entity.EntityType) Profession(org.bukkit.entity.Villager.Profession) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

DyeColor (org.bukkit.DyeColor)2 Color (org.bukkit.entity.Horse.Color)2 Style (org.bukkit.entity.Horse.Style)2 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 Art (org.bukkit.Art)1 ChatColor (org.bukkit.ChatColor)1 EntityType (org.bukkit.entity.EntityType)1 Horse (org.bukkit.entity.Horse)1 ItemFrame (org.bukkit.entity.ItemFrame)1 Ocelot (org.bukkit.entity.Ocelot)1 Type (org.bukkit.entity.Ocelot.Type)1 Painting (org.bukkit.entity.Painting)1 Sheep (org.bukkit.entity.Sheep)1 Skeleton (org.bukkit.entity.Skeleton)1 SkeletonType (org.bukkit.entity.Skeleton.SkeletonType)1 Villager (org.bukkit.entity.Villager)1