diff options
author | md_5 <git@md-5.net> | 2018-12-17 12:30:16 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-12-17 12:36:12 +1100 |
commit | 38cf676e328d869f8d5cded4d9e9ad3d75afb760 (patch) | |
tree | 7dc034c9fb5881789c8cfa60d8369bed07acf8fe /src | |
parent | b446cb5d744836d3de6288da0ef5761dc127a78a (diff) | |
download | craftbukkit-38cf676e328d869f8d5cded4d9e9ad3d75afb760.tar craftbukkit-38cf676e328d869f8d5cded4d9e9ad3d75afb760.tar.gz craftbukkit-38cf676e328d869f8d5cded4d9e9ad3d75afb760.tar.lz craftbukkit-38cf676e328d869f8d5cded4d9e9ad3d75afb760.tar.xz craftbukkit-38cf676e328d869f8d5cded4d9e9ad3d75afb760.zip |
SPIGOT-4534: CreatureSpawnEvent not being called for CHUNK_GEN
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | 41 |
1 files changed, 41 insertions, 0 deletions
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 */ |