3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00

Mark entities as dead when spawning fails. Treat as canceled if entity is dead.

Dieser Commit ist enthalten in:
feildmaster 2012-04-03 17:41:55 -05:00
Ursprung 0c9e1b13a0
Commit af0018a962

Datei anzeigen

@ -23,9 +23,7 @@ import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.ThunderChangeEvent; import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
@ -879,33 +877,34 @@ public class World implements IBlockAccess {
} }
// CraftBukkit start // CraftBukkit start
org.bukkit.event.Cancellable event = null;
if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) { if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) {
boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem; boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem;
boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime; boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime;
if (spawnReason == SpawnReason.NATURAL || spawnReason == SpawnReason.CHUNK_GEN || spawnReason == SpawnReason.JOCKEY || spawnReason == SpawnReason.SPAWNER || spawnReason == SpawnReason.BED || spawnReason == SpawnReason.EGG || spawnReason == SpawnReason.VILLAGE_INVASION || spawnReason == SpawnReason.VILLAGE_DEFENSE || spawnReason == SpawnReason.BUILD_SNOWMAN || spawnReason == SpawnReason.BUILD_IRONGOLEM) { if (spawnReason == SpawnReason.NATURAL || spawnReason == SpawnReason.CHUNK_GEN || spawnReason == SpawnReason.JOCKEY || spawnReason == SpawnReason.SPAWNER || spawnReason == SpawnReason.BED || spawnReason == SpawnReason.EGG || spawnReason == SpawnReason.VILLAGE_INVASION || spawnReason == SpawnReason.VILLAGE_DEFENSE || spawnReason == SpawnReason.BUILD_SNOWMAN || spawnReason == SpawnReason.BUILD_IRONGOLEM) {
if (isAnimal && !allowAnimals || isMonster && !allowMonsters) return false; if (isAnimal && !allowAnimals || isMonster && !allowMonsters) {
entity.dead = true;
return false;
}
} }
CreatureSpawnEvent event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity, spawnReason); event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity, spawnReason);
if (event.isCancelled()) {
return false;
}
} else if (entity instanceof EntityItem) { } else if (entity instanceof EntityItem) {
ItemSpawnEvent event = CraftEventFactory.callItemSpawnEvent((EntityItem) entity); event = CraftEventFactory.callItemSpawnEvent((EntityItem) entity);
if (event.isCancelled()) {
return false;
}
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) { } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) {
// Not all projectiles extend EntityProjectile, so check for Bukkit interface instead // Not all projectiles extend EntityProjectile, so check for Bukkit interface instead
if (CraftEventFactory.callProjectileLaunchEvent(entity).isCancelled()) { event = CraftEventFactory.callProjectileLaunchEvent(entity);
return false; }
}
if (event != null && (event.isCancelled() || entity.dead)) {
entity.dead = true;
return false;
} }
// CraftBukkit end // CraftBukkit end
if (!flag && !this.isChunkLoaded(i, j)) { if (!flag && !this.isChunkLoaded(i, j)) {
entity.dead = true; // CraftBukkit
return false; return false;
} else { } else {
if (entity instanceof EntityHuman) { if (entity instanceof EntityHuman) {