Search in sources :

Example 1 with Ageable

use of org.bukkit.entity.Ageable in project Denizen-For-Bukkit by DenizenScript.

the class EntityAge method setAge.

public void setAge(int val) {
    if (ageable.isCitizensNPC()) {
        NPC ageable_npc = ageable.getDenizenNPC().getCitizen();
        ageable_npc.getTrait(Age.class).setAge(val);
    } else {
        if (ageable.getBukkitEntity().getType() == EntityType.ZOMBIE) {
            ((Zombie) ageable.getBukkitEntity()).setBaby(val >= 0);
        } else {
            ((Ageable) ageable.getBukkitEntity()).setAge(val);
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Zombie(org.bukkit.entity.Zombie) Ageable(org.bukkit.entity.Ageable) Age(net.citizensnpcs.trait.Age)

Example 2 with Ageable

use of org.bukkit.entity.Ageable in project MagicPlugin by elBukkit.

the class FamiliarSpell method onCast.

@SuppressWarnings("deprecation")
@Override
public SpellResult onCast(ConfigurationSection parameters) {
    spawnCount = 0;
    Target target = getTarget();
    if (!target.hasTarget()) {
        return SpellResult.NO_TARGET;
    }
    Block originalTarget = target.getBlock();
    Block targetBlock = originalTarget;
    LivingEntity targetEntity = null;
    boolean track = parameters.getBoolean("track", true);
    boolean loot = parameters.getBoolean("loot", false);
    boolean setTarget = parameters.getBoolean("set_target", true);
    double spawnRange = parameters.getInt("spawn_range", 0);
    String entityName = parameters.getString("name", "");
    if (hasFamiliar() && track) {
        // Dispel familiars if you target them and cast
        boolean isFamiliar = target.hasEntity() && isFamiliar(target.getEntity());
        if (isFamiliar) {
            checkListener();
            releaseFamiliar(target.getEntity());
            return SpellResult.DEACTIVATE;
        }
        releaseFamiliars();
    }
    if (target.hasEntity()) {
        targetBlock = targetBlock.getRelative(BlockFace.SOUTH);
        Entity e = target.getEntity();
        if (e instanceof LivingEntity) {
            targetEntity = (LivingEntity) e;
        }
    }
    targetBlock = targetBlock.getRelative(BlockFace.UP);
    Location centerLoc = targetBlock.getLocation();
    Location caster = getLocation();
    if (spawnRange > 0) {
        double distanceSquared = targetBlock.getLocation().distanceSquared(caster);
        if (spawnRange * spawnRange < distanceSquared) {
            Vector direction = caster.getDirection().normalize().multiply(spawnRange);
            centerLoc = caster.clone().add(direction);
            for (int i = 0; i < spawnRange; i++) {
                Material blockType = centerLoc.getBlock().getType();
                if (blockType == Material.AIR || blockType == Material.WATER || blockType != Material.STATIONARY_WATER) {
                    break;
                }
                centerLoc = centerLoc.add(0, 1, 0);
            }
        }
    }
    EntityType famType = null;
    int famCount = parameters.getInt("count", 1);
    String famTypeName = parameters.getString("type", null);
    if (famTypeName != null && !famTypeName.isEmpty()) {
        try {
            famType = EntityType.valueOf(famTypeName.toUpperCase());
        } catch (Throwable ex) {
            sendMessage("Unknown entity type: " + famTypeName);
            return SpellResult.FAIL;
        }
    }
    if (originalTarget.getType() == Material.WATER || originalTarget.getType() == Material.STATIONARY_WATER) {
        famType = EntityType.SQUID;
    }
    boolean spawnBaby = parameters.getBoolean("baby", false);
    List<LivingEntity> newFamiliars = new ArrayList<>();
    for (int i = 0; i < famCount; i++) {
        EntityType entityType = famType;
        if (entityType == null) {
            String randomType = RandomUtils.weightedRandom(entityTypeProbability);
            try {
                entityType = EntityType.fromName(randomType);
            } catch (Throwable ex) {
                sendMessage("Unknown entity type: " + randomType);
                return SpellResult.FAIL;
            }
        }
        if (parameters.contains("reason")) {
            String reasonText = parameters.getString("reason").toUpperCase();
            try {
                spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
            } catch (Exception ex) {
                sendMessage("Unknown spawn reason: " + reasonText);
                return SpellResult.FAIL;
            }
        }
        final Location targetLoc = centerLoc.clone();
        if (famCount > 1) {
            targetLoc.setX(targetLoc.getX() + rand.nextInt(2 * famCount) - famCount);
            targetLoc.setZ(targetLoc.getZ() + rand.nextInt(2 * famCount) - famCount);
        }
        targetLoc.setPitch(caster.getPitch());
        targetLoc.setYaw(caster.getYaw());
        if (entityType != null) {
            final LivingEntity entity = spawnFamiliar(targetLoc, entityType, targetBlock.getLocation(), targetEntity, setTarget);
            if (entity != null) {
                if (entityName != null && !entityName.isEmpty()) {
                    entity.setCustomName(entityName);
                }
                if (!loot) {
                    entity.setMetadata("nodrops", new FixedMetadataValue(mage.getController().getPlugin(), true));
                }
                if (spawnBaby && entity instanceof Ageable) {
                    Ageable ageable = (Ageable) entity;
                    ageable.setBaby();
                }
                entity.teleport(targetLoc);
                newFamiliars.add(entity);
                spawnCount++;
                registerForUndo(entity);
            }
        }
    }
    registerForUndo();
    if (track) {
        setFamiliars(newFamiliars);
        checkListener();
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Material(org.bukkit.Material) Ageable(org.bukkit.entity.Ageable) LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) Target(com.elmakers.mine.bukkit.utility.Target) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 3 with Ageable

use of org.bukkit.entity.Ageable in project MagicPlugin by elBukkit.

the class GrowEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        context.registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        context.registerModified(li);
        Zombie zombie = (Zombie) li;
        if (!zombie.isBaby()) {
            UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
            Location targetLocation = li.getLocation();
            li.remove();
            Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
            context.registerForUndo(giant);
            if (spawnedList != null) {
                spawnedList.add(giant);
            }
        } else {
            ((Zombie) li).setBaby(false);
        }
    } else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
        context.registerModified(li);
        ((PigZombie) li).setBaby(false);
    } else if (li instanceof Slime) {
        context.registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
        context.registerModified(li);
        Skeleton skeleton = (Skeleton) li;
        skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
    } else {
        return SpellResult.NO_TARGET;
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Skeleton(org.bukkit.entity.Skeleton) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 4 with Ageable

use of org.bukkit.entity.Ageable in project MagicPlugin by elBukkit.

the class GrowSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasEntity()) {
        return SpellResult.NO_TARGET;
    }
    Entity targetEntity = target.getEntity();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        registerModified(li);
        Zombie zombie = (Zombie) li;
        if (!zombie.isBaby()) {
            UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
            Location targetLocation = li.getLocation();
            li.remove();
            Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
            registerForUndo(giant);
            if (spawnedList != null) {
                spawnedList.add(giant);
            }
        } else {
            ((Zombie) li).setBaby(false);
        }
    } else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
        registerModified(li);
        ((PigZombie) li).setBaby(false);
    } else if (li instanceof Slime) {
        registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else {
        return SpellResult.NO_TARGET;
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 5 with Ageable

use of org.bukkit.entity.Ageable in project Citizens2 by CitizensDev.

the class Age method onSpawn.

@Override
public void onSpawn() {
    if (npc.getEntity() instanceof Ageable) {
        Ageable entity = (Ageable) npc.getEntity();
        entity.setAge(age);
        entity.setAgeLock(locked);
        ageable = entity;
    } else if (npc.getEntity() instanceof Zombie) {
        ((Zombie) npc.getEntity()).setBaby(age < 0);
        ageable = null;
    } else {
        ageable = null;
    }
}
Also used : Zombie(org.bukkit.entity.Zombie) Ageable(org.bukkit.entity.Ageable)

Aggregations

Ageable (org.bukkit.entity.Ageable)14 LivingEntity (org.bukkit.entity.LivingEntity)10 Player (org.bukkit.entity.Player)8 Zombie (org.bukkit.entity.Zombie)8 Location (org.bukkit.Location)7 Entity (org.bukkit.entity.Entity)6 Slime (org.bukkit.entity.Slime)5 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)4 PigZombie (org.bukkit.entity.PigZombie)4 Skeleton (org.bukkit.entity.Skeleton)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Target (com.elmakers.mine.bukkit.utility.Target)3 Block (org.bukkit.block.Block)3 EntityType (org.bukkit.entity.EntityType)3 Tameable (org.bukkit.entity.Tameable)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 Age (net.citizensnpcs.trait.Age)2 Projectile (org.bukkit.entity.Projectile)2 Batch (com.elmakers.mine.bukkit.api.batch.Batch)1 BlockData (com.elmakers.mine.bukkit.api.block.BlockData)1