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);
}
}
}
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) {
}
}
}
Aggregations