Search in sources :

Example 1 with ZombieVillager

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

the class EntityInfected method setInfected.

public void setInfected(boolean bool) {
    if (bool) {
        if (infected.isCitizensNPC()) {
            NPC infected_npc = infected.getDenizenNPC().getCitizen();
            infected_npc.setBukkitEntityType(EntityType.ZOMBIE_VILLAGER);
        } else // TODO: Improve upon.
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)) {
            LivingEntity entity = infected.getLivingEntity();
            // Make a new entity
            ZombieVillager infect = (ZombieVillager) entity.getLocation().getWorld().spawnEntity(infected.getLocation(), EntityType.ZOMBIE_VILLAGER);
            // Set health
            infect.setHealth(entity.getHealth());
            // Set equipment
            infect.getEquipment().setArmorContents(entity.getEquipment().getArmorContents());
            // Remove the Villager
            entity.remove();
            // Set the dEntity to the new entity
            infected.setEntity(infect);
        } else // TODO: Improve upon.
        if (infected.getBukkitEntity() instanceof Villager) {
            Villager villager = (Villager) infected.getBukkitEntity();
            // Make a new entity
            Zombie infect = (Zombie) villager.getLocation().getWorld().spawnEntity(infected.getLocation(), EntityType.ZOMBIE);
            infect.setVillager(true);
            // Set health
            infect.setHealth(villager.getHealth());
            // Set equipment
            infect.getEquipment().setArmorContents(villager.getEquipment().getArmorContents());
            // Remove the Villager
            villager.remove();
            // Set the dEntity to the new entity
            infected.setEntity(infect);
        } else // Much much easier
        if (infected.getBukkitEntity() instanceof Zombie) {
            ((Zombie) infected).setVillager(true);
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) LivingEntity(org.bukkit.entity.LivingEntity) Zombie(org.bukkit.entity.Zombie) ZombieVillager(org.bukkit.entity.ZombieVillager) Villager(org.bukkit.entity.Villager) ZombieVillager(org.bukkit.entity.ZombieVillager)

Aggregations

NPC (net.citizensnpcs.api.npc.NPC)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Villager (org.bukkit.entity.Villager)1 Zombie (org.bukkit.entity.Zombie)1 ZombieVillager (org.bukkit.entity.ZombieVillager)1