Search in sources :

Example 1 with Skeleton

use of org.bukkit.entity.Skeleton in project EliteMobs by MagmaGuy.

the class ZombieParents method onHit.

@EventHandler
public void onHit(EntityDamageEvent event) {
    if (event.getEntity().hasMetadata(powerMetadata) && event.getEntity() instanceof Zombie && !event.getEntity().hasMetadata(MetadataHandler.ZOMBIE_PARENTS_ACTIVATED) && random.nextDouble() < 0.5) {
        Entity entity = event.getEntity();
        entity.setMetadata(MetadataHandler.ZOMBIE_PARENTS_ACTIVATED, new FixedMetadataValue(plugin, true));
        int assistMobLevel = (int) Math.floor(entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() / 4);
        if (assistMobLevel < 1) {
            assistMobLevel = 1;
        }
        Skeleton zombieMom = (Skeleton) entity.getWorld().spawnEntity(entity.getLocation(), EntityType.SKELETON);
        Skeleton zombieDad = (Skeleton) entity.getWorld().spawnEntity(entity.getLocation(), EntityType.SKELETON);
        zombieDad.setCustomName(chatColorConverter(configuration.getString("ZombieParents.Dad Name")));
        zombieMom.setCustomName(chatColorConverter(configuration.getString("ZombieParents.Mom Name")));
        zombieDad.setCustomNameVisible(true);
        zombieMom.setCustomNameVisible(true);
        zombieDad.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, assistMobLevel));
        zombieMom.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, assistMobLevel));
        zombieDad.setMetadata(MetadataHandler.FORBIDDEN_MD, new FixedMetadataValue(plugin, true));
        zombieMom.setMetadata(MetadataHandler.FORBIDDEN_MD, new FixedMetadataValue(plugin, true));
        zombieDad.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
        zombieMom.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
        zombieDad.setMetadata(MetadataHandler.CUSTOM_NAME, new FixedMetadataValue(plugin, true));
        zombieMom.setMetadata(MetadataHandler.CUSTOM_NAME, new FixedMetadataValue(plugin, true));
        processID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

            @Override
            public void run() {
                if (!entity.isValid()) {
                    if (zombieDad.isValid()) {
                        nameClearer(zombieDad);
                        zombieDad.setCustomName(chatColorConverter(configuration.getStringList("ZombieParents.DeathMessage").get(random.nextInt(configuration.getStringList("ZombieParents.DeathMessage").size()))));
                    }
                    if (zombieMom.isValid()) {
                        nameClearer(zombieMom);
                        zombieMom.setCustomName(chatColorConverter(configuration.getStringList("ZombieParents.DeathMessage").get(random.nextInt(configuration.getStringList("ZombieParents.DeathMessage").size()))));
                    }
                    Bukkit.getScheduler().cancelTask(processID);
                    return;
                } else {
                    if (random.nextDouble() < 0.5) {
                        nameClearer(entity);
                        entity.setCustomName(chatColorConverter(configuration.getStringList("ZombieParents.ZombieDialog").get(random.nextInt(configuration.getStringList("ZombieParents.ZombieDialog").size()))));
                    }
                    if (random.nextDouble() < 0.5 && zombieDad.isValid()) {
                        nameClearer(zombieDad);
                        zombieDad.setCustomName(chatColorConverter(configuration.getStringList("ZombieParents.ZombieDadDialog").get(random.nextInt(configuration.getStringList("ZombieParents.ZombieDadDialog").size()))));
                    }
                    if (random.nextDouble() < 0.5 && zombieMom.isValid()) {
                        nameClearer(zombieMom);
                        zombieMom.setCustomName(chatColorConverter(configuration.getStringList("ZombieParents.ZombieMomDialog").get(random.nextInt(configuration.getStringList("ZombieParents.ZombieMomDialog").size()))));
                    }
                }
            }
        }, 20, 20 * 8);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Zombie(org.bukkit.entity.Zombie) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Skeleton(org.bukkit.entity.Skeleton) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Skeleton

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

the class EntitySkeleton method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("skeleton") && mechanism.requireEnum(false, Skeleton.SkeletonType.values())) {
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)) {
            // TODO: improve this
            Skeleton.SkeletonType skeletonType = Skeleton.SkeletonType.valueOf(mechanism.getValue().asString().toUpperCase());
            Skeleton current = (Skeleton) skeleton.getBukkitEntity();
            Skeleton newSkeleton = null;
            switch(skeletonType) {
                case NORMAL:
                    newSkeleton = (Skeleton) current.getLocation().getWorld().spawnEntity(current.getLocation(), EntityType.SKELETON);
                    break;
                case WITHER:
                    newSkeleton = (Skeleton) current.getLocation().getWorld().spawnEntity(current.getLocation(), EntityType.WITHER_SKELETON);
                    break;
                case STRAY:
                    newSkeleton = (Skeleton) current.getLocation().getWorld().spawnEntity(current.getLocation(), EntityType.STRAY);
                    break;
            }
            newSkeleton.setHealth(current.getHealth());
            newSkeleton.getEquipment().setArmorContents(current.getEquipment().getArmorContents());
            current.remove();
            skeleton.setEntity(newSkeleton);
        } else {
            ((Skeleton) skeleton.getBukkitEntity()).setSkeletonType(Skeleton.SkeletonType.valueOf(mechanism.getValue().asString().toUpperCase()));
        }
    }
}
Also used : Skeleton(org.bukkit.entity.Skeleton)

Aggregations

Skeleton (org.bukkit.entity.Skeleton)2 Entity (org.bukkit.entity.Entity)1 Zombie (org.bukkit.entity.Zombie)1 EventHandler (org.bukkit.event.EventHandler)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1