From e93061be489dc6f3b4950284e41e50501e55450f Mon Sep 17 00:00:00 2001 From: speakeasy Date: Thu, 20 Jan 2011 05:41:02 +0800 Subject: [PATCH] Fix up NPE's in EntityMinecart/CraftVehicle and removed a little un-needed code in EntityArrow --- src/main/java/net/minecraft/server/EntityArrow.java | 4 +--- src/main/java/net/minecraft/server/EntityMinecart.java | 6 +++++- .../java/org/bukkit/craftbukkit/entity/CraftVehicle.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java index 11ae695470..f068b3fac7 100644 --- a/src/main/java/net/minecraft/server/EntityArrow.java +++ b/src/main/java/net/minecraft/server/EntityArrow.java @@ -178,9 +178,7 @@ public class EntityArrow extends Entity { // or leave as DamageCause.ENTITY_ATTACK org.bukkit.entity.Entity shooter = null; if ((EntityLiving)b != null) { - shooter = new org.bukkit.craftbukkit.entity.CraftLivingEntity(server, b); - } else if ((Entity)b != null) { - shooter = (org.bukkit.entity.Entity) b.getBukkitEntity(); + shooter = b.getBukkitEntity(); } EntityDamageByProjectileEvent edbpe = new EntityDamageByProjectileEvent(shooter, entity.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, 4); diff --git a/src/main/java/net/minecraft/server/EntityMinecart.java b/src/main/java/net/minecraft/server/EntityMinecart.java index ef239f550d..8fdec5c0c8 100644 --- a/src/main/java/net/minecraft/server/EntityMinecart.java +++ b/src/main/java/net/minecraft/server/EntityMinecart.java @@ -183,7 +183,11 @@ public class EntityMinecart extends Entity implements IInventory, CraftMappable public boolean a(Entity entity, int i) { // CraftBukkit start - VehicleDamageEvent event = new VehicleDamageEvent(Type.VEHICLE_DAMAGE, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity(), i); + org.bukkit.entity.Entity passenger = null; + if ((EntityLiving)entity != null) { + passenger = entity.getBukkitEntity(); + } + VehicleDamageEvent event = new VehicleDamageEvent(Type.VEHICLE_DAMAGE, (Vehicle) this.getBukkitEntity(), passenger, i); ((WorldServer)l).getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftVehicle.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftVehicle.java index 04d8d18755..3fbd7c0087 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftVehicle.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftVehicle.java @@ -16,7 +16,7 @@ public abstract class CraftVehicle extends CraftEntity implements Vehicle { } public Entity getPassenger() { - return (getHandle().j.getBukkitEntity()); + return isEmpty()?null:(getHandle().j.getBukkitEntity()); } public boolean setPassenger(Entity passenger) {