From 38cf676e328d869f8d5cded4d9e9ad3d75afb760 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 17 Dec 2018 12:30:16 +1100 Subject: SPIGOT-4534: CreatureSpawnEvent not being called for CHUNK_GEN --- .../craftbukkit/event/CraftEventFactory.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 6890b9b4..a7d88fe6 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -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 */ -- cgit v1.2.3