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

@ -7,8 +7,10 @@ import org.bukkit.craftbukkit.entity.CraftArrow;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
//CraftBukkit end
public class EntityArrow extends Entity {
private int c;
@ -39,30 +41,20 @@ public class EntityArrow extends Entity {
}
public EntityArrow(World world, double d1, double d2, double d3) {
super(world);
c = -1;
d = -1;
e = -1;
f = 0;
ak = false;
a = 0;
am = 0;
a(0.5F, 0.5F);
// CraftBukkit start
this(world);
// CraftBukkit end
a(d1, d2, d3);
H = 0.0F;
}
public EntityArrow(World world, EntityLiving entityliving) {
super(world);
c = -1;
d = -1;
e = -1;
f = 0;
ak = false;
a = 0;
am = 0;
// CraftBukkit start
this(world);
// CraftBukkit end
b = entityliving;
a(0.5F, 0.5F);
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;
@ -176,12 +168,14 @@ public class EntityArrow extends Entity {
//TODO decide if we should create DamageCause.ARROW, DamageCause.PROJECTILE
// or leave as DamageCause.ENTITY_ATTACK
org.bukkit.entity.Entity shooter = null;
if ((EntityLiving)b != null) {
shooter = b.getBukkitEntity();
}
EntityDamageByProjectileEvent edbpe = new EntityDamageByProjectileEvent(shooter, entity.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, 4);
org.bukkit.entity.Entity shooter = (b == null)?null:b.getBukkitEntity();
org.bukkit.entity.Entity damagee = movingobjectposition.g.getBukkitEntity();
org.bukkit.entity.Entity projectile = this.getBukkitEntity();
// TODO deal with arrows being fired from a non-entity
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 4;
EntityDamageByProjectileEvent edbpe = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(edbpe);
if(!edbpe.isCancelled()) {
// this function returns if the arrow should stick in or not, i.e. !bounce

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;

View File

@ -8,8 +8,10 @@ import org.bukkit.craftbukkit.entity.CraftFireball;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
//CraftBukkit end
public class EntityFireball extends Entity {
private int e;
@ -35,6 +37,7 @@ public class EntityFireball extends Entity {
a = 0;
ap = 0;
a(1.0F, 1.0F);
//CraftBukkit start
CraftServer server = ((WorldServer) this.l).getServer();
this.bukkitEntity = new CraftFireball(server, this);
@ -44,16 +47,11 @@ public class EntityFireball extends Entity {
protected void a() {}
public EntityFireball(World world, EntityLiving entityliving, double d1, double d2, double d3) {
super(world);
e = -1;
f = -1;
ak = -1;
al = 0;
am = false;
a = 0;
ap = 0;
// CraftBukkit start
this(world);
// CraftBukkit end
an = entityliving;
a(1.0F, 1.0F);
c(entityliving.p, entityliving.q, entityliving.r, entityliving.v, entityliving.w);
a(p, q, r);
H = 0.0F;
@ -137,11 +135,16 @@ public class EntityFireball extends Entity {
boolean bounce;
if (movingobjectposition.g instanceof EntityLiving) {
CraftServer server = ((WorldServer) this.l).getServer();
org.bukkit.entity.Entity shooter = (an == null)?null:an.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( an.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 fireball should stick or not, i.e. !bounce
bounce = !movingobjectposition.g.a(((Entity) (an)), edbpe.getDamage());

View File

@ -8,6 +8,7 @@ import org.bukkit.craftbukkit.entity.CraftFish;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
//CraftBukkit end
public class EntityFish extends Entity {
@ -51,19 +52,12 @@ public class EntityFish extends Entity {
protected void a() {}
public EntityFish(World world, EntityPlayer entityplayer) {
super(world);
d = -1;
e = -1;
f = -1;
ak = 0;
al = false;
a = 0;
an = 0;
ao = 0;
c = null;
// CraftBukkit start
this(world);
// CraftBukkit end
b = entityplayer;
b.aE = this;
a(0.25F, 0.25F);
c(entityplayer.p, (entityplayer.q + 1.6200000000000001D) - (double) entityplayer.H, entityplayer.r, entityplayer.v, entityplayer.w);
p -= MathHelper.b((v / 180F) * 3.141593F) * 0.16F;
q -= 0.10000000149011612D;
@ -207,11 +201,16 @@ public class EntityFish extends Entity {
boolean bounce;
if (movingobjectposition.g instanceof EntityLiving) {
CraftServer server = ((WorldServer) this.l).getServer();
org.bukkit.entity.Entity shooter = (b == null)?null:b.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(b.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 fish should stick or not, i.e. !bounce
bounce = !movingobjectposition.g.a(((Entity) (b)), edbpe.getDamage());

View File

@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.entity.CraftSnowball;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
//CraftBukkit end
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public class EntitySnowball extends Entity {
@ -41,16 +42,11 @@ public class EntitySnowball extends Entity {
protected void a() {}
public EntitySnowball(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;
@ -66,16 +62,11 @@ public class EntitySnowball extends Entity {
}
public EntitySnowball(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;
}
@ -175,11 +166,16 @@ public class EntitySnowball 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 snowball should stick or not, i.e. !bounce
bounce = !movingobjectposition.g.a(((Entity) (ak)), edbpe.getDamage());