Search in sources :

Example 1 with Villager

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

Example 2 with Villager

use of org.bukkit.entity.Villager in project Towny by ElgarL.

the class TownyEntityListener method onCreatureSpawn.

/**
	 * 
	 * @param event
	 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    if (event.getEntity() instanceof LivingEntity) {
        LivingEntity livingEntity = (LivingEntity) event.getEntity();
        Location loc = event.getLocation();
        Coord coord = Coord.parseCoord(loc);
        TownyWorld townyWorld = null;
        try {
            townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
        } catch (NotRegisteredException e) {
            // Failed to fetch a world
            return;
        }
        // remove from world if set to remove mobs globally
        if (townyWorld.isUsingTowny())
            if (!townyWorld.hasWorldMobs() && ((MobRemovalTimerTask.isRemovingWorldEntity(livingEntity) || ((livingEntity instanceof Villager) && !((Villager) livingEntity).isAdult() && (TownySettings.isRemovingVillagerBabiesWorld()))))) {
                if (plugin.isCitizens2()) {
                    if (!CitizensAPI.getNPCRegistry().isNPC(livingEntity)) {
                        // TownyMessaging.sendDebugMsg("onCreatureSpawn world: Canceled "
                        // + event.getEntityType().name() +
                        // " from spawning within "+coord.toString()+".");
                        event.setCancelled(true);
                    }
                } else
                    event.setCancelled(true);
            }
        // remove from towns if in the list and set to remove
        try {
            TownBlock townBlock = townyWorld.getTownBlock(coord);
            if (townyWorld.isUsingTowny() && !townyWorld.isForceTownMobs()) {
                if (!townBlock.getTown().hasMobs() && !townBlock.getPermissions().mobs) {
                    if ((MobRemovalTimerTask.isRemovingTownEntity(livingEntity) || ((livingEntity instanceof Villager) && !((Villager) livingEntity).isAdult() && (TownySettings.isRemovingVillagerBabiesTown())))) {
                        if (plugin.isCitizens2()) {
                            if (!CitizensAPI.getNPCRegistry().isNPC(livingEntity)) {
                                // TownyMessaging.sendDebugMsg("onCreatureSpawn town: Canceled "
                                // + event.getEntityType().name() +
                                // " from spawning within "+coord.toString()+".");
                                event.setCancelled(true);
                            }
                        } else
                            event.setCancelled(true);
                    }
                }
            }
        } catch (TownyException x) {
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Coord(com.palmergames.bukkit.towny.object.Coord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Villager(org.bukkit.entity.Villager) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)2 Villager (org.bukkit.entity.Villager)2 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 Coord (com.palmergames.bukkit.towny.object.Coord)1 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)1 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)1 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)1 NPC (net.citizensnpcs.api.npc.NPC)1 Location (org.bukkit.Location)1 Zombie (org.bukkit.entity.Zombie)1 ZombieVillager (org.bukkit.entity.ZombieVillager)1 EventHandler (org.bukkit.event.EventHandler)1