Add a NPE check to getVehicle

This commit is contained in:
fullwall 2018-03-02 00:39:05 +08:00
parent d14119bc38
commit bf13181bd1
4 changed files with 13 additions and 2 deletions

View File

@ -505,6 +505,9 @@ public class NMSImpl implements NMSBridge {
@Override @Override
public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) { public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity); Entity handle = NMSImpl.getHandle(entity);
if (handle == null) {
return null;
}
Entity e = handle.getVehicle(); Entity e = handle.getVehicle();
return (e == handle || e == null) ? null : e.getBukkitEntity(); return (e == handle || e == null) ? null : e.getBukkitEntity();
} }

View File

@ -547,6 +547,9 @@ public class NMSImpl implements NMSBridge {
@Override @Override
public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) { public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity); Entity handle = NMSImpl.getHandle(entity);
if (handle == null) {
return null;
}
Entity e = handle.getVehicle(); Entity e = handle.getVehicle();
return (e == handle || e == null) ? null : e.getBukkitEntity(); return (e == handle || e == null) ? null : e.getBukkitEntity();
} }

View File

@ -84,8 +84,9 @@ public class OcelotController extends MobEntityController {
// this method is called by both the entities involved - cancelling // this method is called by both the entities involved - cancelling
// it will not stop the NPC from moving. // it will not stop the NPC from moving.
super.collide(entity); super.collide(entity);
if (npc != null) if (npc != null) {
Util.callCollisionEvent(npc, entity.getBukkitEntity()); Util.callCollisionEvent(npc, entity.getBukkitEntity());
}
} }
@Override @Override
@ -188,8 +189,9 @@ public class OcelotController extends MobEntityController {
@Override @Override
public void M() { public void M() {
super.M(); super.M();
if (npc != null) if (npc != null) {
npc.update(); npc.update();
}
} }
@Override @Override

View File

@ -551,6 +551,9 @@ public class NMSImpl implements NMSBridge {
@Override @Override
public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) { public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity); Entity handle = NMSImpl.getHandle(entity);
if (handle == null) {
return null;
}
Entity e = handle.getVehicle(); Entity e = handle.getVehicle();
return (e == handle || e == null) ? null : e.getBukkitEntity(); return (e == handle || e == null) ? null : e.getBukkitEntity();
} }