SPIGOT-4534: CreatureSpawnEvent not being called for CHUNK_GEN

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2018-12-17 12:30:16 +11:00
parent ee3eaaf511
commit 0d2bc86153
3 changed files with 100 additions and 71 deletions

View File

@@ -359,6 +359,47 @@ public class CraftEventFactory {
return event;
}
public static boolean doEntityAddEventCalling(World world, Entity entity, SpawnReason spawnReason){
if (entity == null) return false;
org.bukkit.event.Cancellable event = null;
if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) {
boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem;
boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime;
boolean isNpc = entity instanceof NPC;
if (spawnReason != SpawnReason.CUSTOM) {
if (isAnimal && !world.allowAnimals || isMonster && !world.allowMonsters || isNpc && !world.getServer().getServer().getSpawnNPCs()) {
entity.dead = true;
return false;
}
}
event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity, spawnReason);
} else if (entity instanceof EntityItem) {
event = CraftEventFactory.callItemSpawnEvent((EntityItem) entity);
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) {
// Not all projectiles extend EntityProjectile, so check for Bukkit interface instead
event = CraftEventFactory.callProjectileLaunchEvent(entity);
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle){
event = CraftEventFactory.callVehicleCreateEvent(entity);
}
if (event != null && (event.isCancelled() || entity.dead)) {
Entity vehicle = entity.getVehicle();
if (vehicle != null) {
vehicle.dead = true;
}
for (Entity passenger : entity.getAllPassengers()) {
passenger.dead = true;
}
entity.dead = true;
return false;
}
return true;
}
/**
* CreatureSpawnEvent
*/