Use the root vehicle for NPC#teleport

This commit is contained in:
fullwall 2013-08-02 15:14:58 +08:00
parent 59af96c467
commit 93495a9ab9
2 changed files with 9 additions and 1 deletions

View File

@ -215,7 +215,7 @@ public class CitizensNPC extends AbstractNPC {
public void teleport(Location location, TeleportCause cause) {
if (!this.isSpawned())
return;
teleport(getBukkitEntity(), location, false, 5);
teleport(NMS.getRootVehicle(getBukkitEntity()), location, false, 5);
}
@Override

View File

@ -156,6 +156,14 @@ public class NMS {
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null;
}
public static org.bukkit.entity.Entity getRootVehicle(org.bukkit.entity.Entity entity) {
Entity handle = NMS.getHandle(entity);
while (handle.vehicle != null) {
handle = handle.vehicle;
}
return handle.getBukkitEntity();
}
public static float getSpeedFor(NPC npc) {
if (!npc.isSpawned())
return DEFAULT_SPEED;