Fixes to projectile events to check for null entities.

This commit is contained in:
Andrew Ardill
2011-01-20 20:26:19 +11:00
parent cbebfbd6da
commit 11de6b91da
5 changed files with 82 additions and 91 deletions

View File

@@ -11,6 +11,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.Event.Type;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerEggThrowEvent;
// CraftBukkit end
@@ -45,16 +46,11 @@ public class EntityEgg extends Entity {
protected void a() {}
public EntityEgg(World world, EntityLiving entityliving) {
super(world);
b = -1;
c = -1;
d = -1;
e = 0;
f = false;
a = 0;
am = 0;
// CraftBukkit start
this(world);
// CraftBukkit end
ak = entityliving;
a(0.25F, 0.25F);
c(entityliving.p, entityliving.q + (double) entityliving.w(), entityliving.r, entityliving.v, entityliving.w);
p -= MathHelper.b((v / 180F) * 3.141593F) * 0.16F;
q -= 0.10000000149011612D;
@@ -70,16 +66,11 @@ public class EntityEgg extends Entity {
}
public EntityEgg(World world, double d1, double d2, double d3) {
super(world);
b = -1;
c = -1;
d = -1;
e = 0;
f = false;
a = 0;
am = 0;
// CraftBukkit start
this(world);
// CraftBukkit end
al = 0;
a(0.25F, 0.25F);
a(d1, d2, d3);
H = 0.0F;
}
@@ -179,11 +170,16 @@ public class EntityEgg extends Entity {
boolean bounce;
if (movingobjectposition.g instanceof EntityLiving) {
CraftServer server = ((WorldServer) this.l).getServer();
org.bukkit.entity.Entity shooter = (ak == null)?null:ak.getBukkitEntity();
org.bukkit.entity.Entity damagee = movingobjectposition.g.getBukkitEntity();
org.bukkit.entity.Entity projectile = this.getBukkitEntity();
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 0;
//TODO @see EntityArrow#162
EntityDamageByProjectileEvent edbpe = new EntityDamageByProjectileEvent( ak.getBukkitEntity(), movingobjectposition.g.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, 0);
EntityDamageByProjectileEvent edbpe = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(edbpe);
if(!edbpe.isCancelled()) {
// this function returns if the egg should stick or not, i.e. !bounce
bounce = !movingobjectposition.g.a(((Entity) (ak)), edbpe.getDamage());
@@ -206,21 +202,24 @@ public class EntityEgg extends Entity {
if (!hatching) {
numHatching = 0;
}
MobType type = MobType.CHICKEN;
MobType hatchingType = MobType.CHICKEN;
if (ak instanceof EntityPlayerMP) {
CraftServer server = ((WorldServer) l).getServer();
PlayerEggThrowEvent event = new PlayerEggThrowEvent(Type.PLAYER_EGG_THROW, (Player) ak.getBukkitEntity(), hatching, numHatching, type);
Type eventType = Type.PLAYER_EGG_THROW;
Player player = (Player) ak.getBukkitEntity();
PlayerEggThrowEvent event = new PlayerEggThrowEvent(eventType, player, hatching, numHatching, hatchingType);
server.getPluginManager().callEvent(event);
hatching = event.isHatching();
numHatching = event.getNumHatches();
type = event.getHatchType();
hatchingType = event.getHatchType();
}
if (hatching) {
for (int k = 0; k < numHatching; k++) {
Entity entity = null;
switch (type) {
switch (hatchingType) {
case CHICKEN:
entity = new EntityChicken(this.l);
break;