diff options
author | aPunch <alexpuncochar@yahoo.com> | 2012-02-16 15:12:47 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-23 15:07:41 -0500 |
commit | 036b5c39560eae88667f807b7ee9908dac125a5d (patch) | |
tree | cab1c2d5d20722c46f3a434a4df732cc4e024a18 /src/main | |
parent | af51313ffb1b13de031ad66512c1cd2722a1c730 (diff) | |
download | craftbukkit-036b5c39560eae88667f807b7ee9908dac125a5d.tar craftbukkit-036b5c39560eae88667f807b7ee9908dac125a5d.tar.gz craftbukkit-036b5c39560eae88667f807b7ee9908dac125a5d.tar.lz craftbukkit-036b5c39560eae88667f807b7ee9908dac125a5d.tar.xz craftbukkit-036b5c39560eae88667f807b7ee9908dac125a5d.zip |
[Bleeding] Added launchProjectile.
Use launchProjectile in place of individual throwSnowball, throwEgg, and shootArrow methods.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index cbf5c1c2..9f69d74f 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.entity; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -8,30 +9,37 @@ import java.util.List; import net.minecraft.server.DamageSource; import net.minecraft.server.EntityArrow; import net.minecraft.server.EntityEgg; +import net.minecraft.server.EntityEnderPearl; +import net.minecraft.server.EntityFireball; import net.minecraft.server.EntityLiving; +import net.minecraft.server.EntitySmallFireball; +import net.minecraft.server.EntitySnowball; import net.minecraft.server.EntityPlayer; import net.minecraft.server.MobEffect; import net.minecraft.server.MobEffectList; -import net.minecraft.server.EntitySnowball; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; - import org.bukkit.entity.Arrow; import org.bukkit.entity.Egg; import org.bukkit.entity.EntityType; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.SmallFireball; import org.bukkit.entity.Snowball; import org.bukkit.entity.Vehicle; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.BlockIterator; +import org.bukkit.util.Vector; -import java.util.Collection; +import org.apache.commons.lang.Validate; public class CraftLivingEntity extends CraftEntity implements LivingEntity { public CraftLivingEntity(final CraftServer server, final EntityLiving entity) { @@ -58,20 +66,14 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return getHandle().getMaxHealth(); } + @Deprecated public Egg throwEgg() { - net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle(); - EntityEgg egg = new EntityEgg(world, getHandle()); - - world.addEntity(egg); - return (Egg) egg.getBukkitEntity(); + return launchProjectile(Egg.class); } + @Deprecated public Snowball throwSnowball() { - net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle(); - EntitySnowball snowball = new EntitySnowball(world, getHandle()); - - world.addEntity(snowball); - return (Snowball) snowball.getBukkitEntity(); + return launchProjectile(Snowball.class); } public double getEyeHeight() { @@ -121,12 +123,9 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return getLineOfSight(transparent, maxDistance, 2); } + @Deprecated public Arrow shootArrow() { - net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle(); - EntityArrow arrow = new EntityArrow(world, getHandle(), 1); - - world.addEntity(arrow); - return (Arrow) arrow.getBukkitEntity(); + return launchProjectile(Arrow.class); } public boolean isInsideVehicle() { @@ -277,6 +276,37 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return effects; } + @SuppressWarnings("unchecked") + public <T extends Projectile> T launchProjectile(Class<? extends T> projectile) { + net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle(); + net.minecraft.server.Entity launch = null; + + if (Snowball.class.isAssignableFrom(projectile)) { + launch = new EntitySnowball(world, getHandle()); + } else if (Egg.class.isAssignableFrom(projectile)) { + launch = new EntityEgg(world, getHandle()); + } else if (EnderPearl.class.isAssignableFrom(projectile)) { + launch = new EntityEnderPearl(world, getHandle()); + } else if (Arrow.class.isAssignableFrom(projectile)) { + launch = new EntityArrow(world, getHandle(), 1); + } else if (Fireball.class.isAssignableFrom(projectile)) { + if (SmallFireball.class.isAssignableFrom(projectile)) { + launch = new EntitySmallFireball(world); + } else { + launch = new EntityFireball(world); + } + + launch.setPositionRotation(getLocation().getX(), getLocation().getY(), getLocation().getZ(), getLocation().getYaw(), getLocation().getPitch()); + Vector direction = getLocation().getDirection().multiply(10); + ((EntityFireball) launch).setDirection(direction.getX(), direction.getY(), direction.getZ()); + } + + Validate.notNull(launch, "Projectile not supported"); + + world.addEntity(launch); + return (T) launch.getBukkitEntity(); + } + public EntityType getType() { return EntityType.UNKNOWN; } |