diff options
author | sunkid <sunkid@iminurnetz.com> | 2011-06-08 15:47:27 -0700 |
---|---|---|
committer | EvilSeph <evilseph@unaligned.org> | 2011-06-17 01:57:33 -0400 |
commit | a70a5abc3d44cc7ac8b414d533463f2c5f87c15e (patch) | |
tree | ffa49a0489bdf4b9b33fa9f23caac089849a77c2 /src/main | |
parent | a8817b7bd10b2b716d849d5fb5e05566107cb2e3 (diff) | |
download | craftbukkit-a70a5abc3d44cc7ac8b414d533463f2c5f87c15e.tar craftbukkit-a70a5abc3d44cc7ac8b414d533463f2c5f87c15e.tar.gz craftbukkit-a70a5abc3d44cc7ac8b414d533463f2c5f87c15e.tar.lz craftbukkit-a70a5abc3d44cc7ac8b414d533463f2c5f87c15e.tar.xz craftbukkit-a70a5abc3d44cc7ac8b414d533463f2c5f87c15e.zip |
Added implementation of general spawn method.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 145 |
1 files changed, 115 insertions, 30 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index e1ac08ab..486d939e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -307,46 +307,36 @@ public class CraftWorld implements World { return (Arrow) arrow.getBukkitEntity(); } + /** + * @deprecated use {@link #spawn(Location, Class)} instead + */ + @Deprecated public Minecart spawnMinecart(Location loc) { - EntityMinecart minecart = new EntityMinecart( - world, - loc.getX(), - loc.getY(), - loc.getZ(), - CraftMinecart.Type.Minecart.getId() - ); - world.addEntity(minecart); - return (Minecart) minecart.getBukkitEntity(); + return spawn(loc, Minecart.class); } + /** + * @deprecated use {@link #spawn(Location, Class)} instead + */ + @Deprecated public StorageMinecart spawnStorageMinecart(Location loc) { - EntityMinecart minecart = new EntityMinecart( - world, - loc.getX(), - loc.getY(), - loc.getZ(), - CraftMinecart.Type.StorageMinecart.getId() - ); - world.addEntity(minecart); - return (StorageMinecart) minecart.getBukkitEntity(); + return spawn(loc, StorageMinecart.class); } + /** + * @deprecated use {@link #spawn(Location, Class)} instead + */ + @Deprecated public PoweredMinecart spawnPoweredMinecart(Location loc) { - EntityMinecart minecart = new EntityMinecart( - world, - loc.getX(), - loc.getY(), - loc.getZ(), - CraftMinecart.Type.PoweredMinecart.getId() - ); - world.addEntity(minecart); - return (PoweredMinecart) minecart.getBukkitEntity(); + return spawn(loc, PoweredMinecart.class); } + /** + * @deprecated use {@link #spawn(Location, Class)} instead + */ + @Deprecated public Boat spawnBoat(Location loc) { - EntityBoat boat = new EntityBoat(world, loc.getX(), loc.getY(), loc.getZ()); - world.addEntity(boat); - return (Boat) boat.getBukkitEntity(); + return spawn(loc, Boat.class); } public LivingEntity spawnCreature(Location loc, CreatureType creatureType) { @@ -675,4 +665,99 @@ public class CraftWorld implements World { } } } + + @SuppressWarnings("unchecked") + public <T extends Entity> T spawn(Location location, Class<T> clazz) throws IllegalArgumentException { + if (location == null || clazz == null) { + throw new IllegalArgumentException("Location or entity class cannot be null"); + } + + net.minecraft.server.Entity entity = null; + + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + float pitch = location.getPitch(); + float yaw = location.getYaw(); + + // order is important for some of these + if (clazz.isAssignableFrom(Boat.class)) { + entity = new EntityBoat(world, x, y, z); + } else if (clazz.isAssignableFrom(Egg.class)) { + entity = new EntityEgg(world, x, y, z); + } else if (clazz.isAssignableFrom(FallingSand.class)) { + entity = new EntityFallingSand(world, x, y, z, 0); + } else if (clazz.isAssignableFrom(Fireball.class)) { + // need a shooter + } else if (clazz.isAssignableFrom(Snowball.class)) { + entity = new EntitySnowball(world, x, y, z); + } else if (Minecart.class.isAssignableFrom(clazz)) { + + if (clazz.isAssignableFrom(PoweredMinecart.class)) { + entity = new EntityMinecart(world, x, y, z, CraftMinecart.Type.PoweredMinecart.getId()); + } else if (clazz.isAssignableFrom(StorageMinecart.class)) { + entity = new EntityMinecart(world, x, y, z, CraftMinecart.Type.StorageMinecart.getId()); + } else { + entity = new EntityMinecart(world, x, y, z, CraftMinecart.Type.Minecart.getId()); + } + + } else if (clazz.isAssignableFrom(Arrow.class)) { + entity = new EntityArrow(world); + entity.setPositionRotation(x, y, z, 0, 0); + } else if (LivingEntity.class.isAssignableFrom(clazz)) { + + if (clazz.isAssignableFrom(Chicken.class)) { + entity = new EntityChicken(world); + } else if (clazz.isAssignableFrom(Cow.class)) { + entity = new EntityCow(world); + } else if (clazz.isAssignableFrom(Creeper.class)) { + entity = new EntityCreeper(world); + } else if (clazz.isAssignableFrom(Fish.class)) { + entity = new EntityFish(world); + } else if (clazz.isAssignableFrom(Ghast.class)) { + entity = new EntityGhast(world); + } else if (clazz.isAssignableFrom(Pig.class)) { + entity = new EntityGhast(world); + } else if (clazz.isAssignableFrom(Player.class)) { + // need a net server handler for this one + } else if (clazz.isAssignableFrom(Sheep.class)) { + entity = new EntitySheep(world); + } else if (clazz.isAssignableFrom(Skeleton.class)) { + entity = new EntitySkeleton(world); + } else if (clazz.isAssignableFrom(Slime.class)) { + entity = new EntitySlime(world); + } else if (clazz.isAssignableFrom(Spider.class)) { + entity = new EntitySpider(world); + } else if (clazz.isAssignableFrom(Squid.class)) { + entity = new EntitySquid(world); + } else if (clazz.isAssignableFrom(Wolf.class)) { + entity = new EntityWolf(world); + } else if (clazz.isAssignableFrom(PigZombie.class)) { + entity = new EntityPigZombie(world); + } else if (clazz.isAssignableFrom(Zombie.class)) { + entity = new EntityZombie(world); + } + + if (entity != null) { + entity.setLocation(x, y, z, pitch, yaw); + } + + } else if (clazz.isAssignableFrom(Painting.class)) { + // negative + } else if (clazz.isAssignableFrom(TNTPrimed.class)) { + entity = new EntityTNTPrimed(world, x, y, z); + } else if (clazz.isAssignableFrom(Weather.class)) { + // not sure what this can do + entity = new EntityWeatherStorm(world, x, y, z); + } else if (clazz.isAssignableFrom(LightningStrike.class)) { + // what is this, I don't even + } + + if (entity != null) { + world.addEntity(entity); + return (T) entity.getBukkitEntity(); + } + + throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName()); + } } |