diff options
author | lem21h <lem21h@anon> | 2011-03-20 21:18:38 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-03-23 19:17:14 +0100 |
commit | fdcf1c3c3aa81f9524ef1534c3fe1142b290530e (patch) | |
tree | d838ec604d646b2e6460731e42dd4787a6fbdc2a /src | |
parent | 15baff85595bbc72dad66f185d7921d8548c82b6 (diff) | |
download | craftbukkit-fdcf1c3c3aa81f9524ef1534c3fe1142b290530e.tar craftbukkit-fdcf1c3c3aa81f9524ef1534c3fe1142b290530e.tar.gz craftbukkit-fdcf1c3c3aa81f9524ef1534c3fe1142b290530e.tar.lz craftbukkit-fdcf1c3c3aa81f9524ef1534c3fe1142b290530e.tar.xz craftbukkit-fdcf1c3c3aa81f9524ef1534c3fe1142b290530e.zip |
Now also handle entities spawning on a loading a world. (Redacted by Grum)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/World.java | 58 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | 60 |
2 files changed, 77 insertions, 41 deletions
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index f75b320d..2cb91c0c 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -12,6 +12,7 @@ import java.util.TreeSet; import org.bukkit.Location; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.entity.CreatureType; import org.bukkit.event.Event; import org.bukkit.event.Event.Type; @@ -721,45 +722,9 @@ public class World implements IBlockAccess { // CraftBukkit start if (entity instanceof EntityLiving) { - - CreatureType type = null; - - if (entity instanceof EntityChicken) { - type = CreatureType.CHICKEN; - } else if (entity instanceof EntityCow) { - type = CreatureType.COW; - } else if (entity instanceof EntityCreeper) { - type = CreatureType.CREEPER; - } else if (entity instanceof EntityGhast) { - type = CreatureType.GHAST; - } else if (entity instanceof EntityPig) { - type = CreatureType.PIG; - } else if (entity instanceof EntityPigZombie) { - type = CreatureType.PIG_ZOMBIE; - } else if (entity instanceof EntitySheep) { - type = CreatureType.SHEEP; - } else if (entity instanceof EntitySkeleton) { - type = CreatureType.SKELETON; - } else if (entity instanceof EntitySpider) { - type = CreatureType.SPIDER; - } else if (entity instanceof EntityZombie) { - type = CreatureType.ZOMBIE; - } else if (entity instanceof EntitySlime) { - type = CreatureType.SLIME; - } else if (entity instanceof EntitySquid) { - type = CreatureType.SQUID; - } - - if (type != null) { - CraftServer server = ((WorldServer) this).getServer(); - Location loc = new Location(((WorldServer) this).getWorld(), entity.bi, entity.bj, entity.bk); - - CreatureSpawnEvent event = new CreatureSpawnEvent(entity.getBukkitEntity(), type, loc); - server.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return false; - } + CreatureSpawnEvent event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity); + if (event.isCancelled()) { + return false; } } // CraftBukkit end @@ -1609,9 +1574,20 @@ public class World implements IBlockAccess { } public void a(List list) { - this.b.addAll(list); - + // CraftBukkit start + Entity entity = null; for (int i = 0; i < list.size(); ++i) { + entity = (Entity) list.get(i); + // CraftBukkit start + if (entity instanceof EntityLiving) { + CreatureSpawnEvent event = CraftEventFactory.callCreatureSpawnEvent((EntityLiving) entity); + if (event.isCancelled()) { + continue; + } + } + + this.b.add(entity); + // CraftBukkit end this.b((Entity) list.get(i)); } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 433cc33f..c3dbd0d9 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -1,12 +1,26 @@ package org.bukkit.craftbukkit.event;
import net.minecraft.server.ChunkCoordinates;
+import net.minecraft.server.EntityChicken;
+import net.minecraft.server.EntityCow;
+import net.minecraft.server.EntityCreeper;
+import net.minecraft.server.EntityGhast;
import net.minecraft.server.EntityHuman;
+import net.minecraft.server.EntityLiving;
+import net.minecraft.server.EntityPig;
+import net.minecraft.server.EntityPigZombie;
+import net.minecraft.server.EntitySheep;
+import net.minecraft.server.EntitySkeleton;
+import net.minecraft.server.EntitySlime;
+import net.minecraft.server.EntitySpider;
+import net.minecraft.server.EntitySquid;
+import net.minecraft.server.EntityZombie;
import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;
import net.minecraft.server.World;
import net.minecraft.server.WorldServer;
+import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -15,11 +29,14 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.CreatureType;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerEvent;
@@ -146,6 +163,9 @@ public class CraftEventFactory { return event; }
+ /**
+ * BlockDamageEvent
+ */
public static BlockDamageEvent callBlockDamageEvent(EntityHuman who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = new CraftItemStack(itemstack);
@@ -160,4 +180,44 @@ public class CraftEventFactory { return event;
}
+
+ /**
+ * CreatureSpawnEvent
+ */
+ public static CreatureSpawnEvent callCreatureSpawnEvent(EntityLiving entityliving) {
+ org.bukkit.entity.Entity entity = entityliving.getBukkitEntity();
+ CraftServer craftServer = (CraftServer) entity.getServer();
+
+ CreatureType type = null;
+
+ if (entity instanceof EntityChicken) {
+ type = CreatureType.CHICKEN;
+ } else if (entity instanceof EntityCow) {
+ type = CreatureType.COW;
+ } else if (entity instanceof EntityCreeper) {
+ type = CreatureType.CREEPER;
+ } else if (entity instanceof EntityGhast) {
+ type = CreatureType.GHAST;
+ } else if (entity instanceof EntityPig) {
+ type = CreatureType.PIG;
+ } else if (entity instanceof EntityPigZombie) {
+ type = CreatureType.PIG_ZOMBIE;
+ } else if (entity instanceof EntitySheep) {
+ type = CreatureType.SHEEP;
+ } else if (entity instanceof EntitySkeleton) {
+ type = CreatureType.SKELETON;
+ } else if (entity instanceof EntitySheep) {
+ type = CreatureType.SPIDER;
+ } else if (entity instanceof EntityZombie) {
+ type = CreatureType.ZOMBIE;
+ } else if (entity instanceof EntitySlime) {
+ type = CreatureType.SLIME;
+ } else if (entity instanceof EntitySquid) {
+ type = CreatureType.SQUID;
+ }
+
+ CreatureSpawnEvent event = new CreatureSpawnEvent(entity, type, entity.getLocation());
+ craftServer.getPluginManager().callEvent(event);
+ return event;
+ }
}
|