Search in sources :

Example 1 with Profession

use of org.bukkit.entity.Villager.Profession in project Citizens2 by CitizensDev.

the class NPCCommands method profession.

@Command(aliases = { "npc" }, usage = "profession|prof [profession]", desc = "Set a NPC's profession", modifiers = { "profession", "prof" }, min = 2, max = 2, permission = "citizens.npc.profession")
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER })
public void profession(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String profession = args.getString(1);
    Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
    if (parsed == null) {
        throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1), StringUtils.join(Profession.values(), ","));
    }
    npc.getTrait(VillagerProfession.class).setProfession(parsed);
    Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
}
Also used : Profession(org.bukkit.entity.Villager.Profession) VillagerProfession(net.citizensnpcs.trait.VillagerProfession) VillagerProfession(net.citizensnpcs.trait.VillagerProfession) 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 Profession

use of org.bukkit.entity.Villager.Profession 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

Profession (org.bukkit.entity.Villager.Profession)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 VillagerProfession (net.citizensnpcs.trait.VillagerProfession)1 Art (org.bukkit.Art)1 DyeColor (org.bukkit.DyeColor)1 EntityType (org.bukkit.entity.EntityType)1 Horse (org.bukkit.entity.Horse)1 Color (org.bukkit.entity.Horse.Color)1 Style (org.bukkit.entity.Horse.Style)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