Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Mark entities as dead when spawning fails. Treat as canceled if entit…

…y is dead.
  • Loading branch information...
commit e270ce04a389f69d2ca4b15c6372294875d7c900 1 parent e1b9af9
authored April 03, 2012
29  src/main/java/net/minecraft/server/World.java
@@ -23,9 +23,7 @@
23 23
 import org.bukkit.event.block.BlockCanBuildEvent;
24 24
 import org.bukkit.event.block.BlockPhysicsEvent;
25 25
 import org.bukkit.event.block.BlockFormEvent;
26  
-import org.bukkit.event.entity.CreatureSpawnEvent;
27 26
 import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
28  
-import org.bukkit.event.entity.ItemSpawnEvent;
29 27
 import org.bukkit.event.weather.WeatherChangeEvent;
30 28
 import org.bukkit.event.weather.ThunderChangeEvent;
31 29
 import org.bukkit.block.BlockState;
@@ -879,33 +877,34 @@ public boolean addEntity(Entity entity, SpawnReason spawnReason) { // Changed si
879 877
         }
880 878
 
881 879
         // CraftBukkit start
  880
+        org.bukkit.event.Cancellable event = null;
882 881
         if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) {
883 882
             boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem;
884 883
             boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime;
885 884
 
886 885
             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) {
887  
-                if (isAnimal && !allowAnimals || isMonster && !allowMonsters) return false;
  886
+                if (isAnimal && !allowAnimals || isMonster && !allowMonsters)  {
  887
+                    entity.dead = true;
  888
+                    return false;
  889
+                }
888 890
             }
889 891
 
890  
-            CreatureSpawnEvent event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity, spawnReason);
891  
-
892  
-            if (event.isCancelled()) {
893  
-                return false;
894  
-            }
  892
+            event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity, spawnReason);
895 893
         } else if (entity instanceof EntityItem) {
896  
-            ItemSpawnEvent event = CraftEventFactory.callItemSpawnEvent((EntityItem) entity);
897  
-            if (event.isCancelled()) {
898  
-                return false;
899  
-            }
  894
+            event = CraftEventFactory.callItemSpawnEvent((EntityItem) entity);
900 895
         } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) {
901 896
             // Not all projectiles extend EntityProjectile, so check for Bukkit interface instead
902  
-            if (CraftEventFactory.callProjectileLaunchEvent(entity).isCancelled()) {
903  
-                return false;
904  
-            }
  897
+            event = CraftEventFactory.callProjectileLaunchEvent(entity);
  898
+        }
  899
+
  900
+        if (event != null && (event.isCancelled() || entity.dead)) {
  901
+            entity.dead = true;
  902
+            return false;
905 903
         }
906 904
         // CraftBukkit end
907 905
 
908 906
         if (!flag && !this.isChunkLoaded(i, j)) {
  907
+            entity.dead = true; // CraftBukkit
909 908
             return false;
910 909
         } else {
911 910
             if (entity instanceof EntityHuman) {

0 notes on commit e270ce0

Please sign in to comment.
Something went wrong with that request. Please try again.