Don't teleport if despawned

This commit is contained in:
fullwall 2020-07-15 23:50:48 +08:00
parent 0036c9d6a2
commit 57373a68a3

View File

@ -326,6 +326,8 @@ public class CitizensNPC extends AbstractNPC {
@Override @Override
public void teleport(Location location, TeleportCause reason) { public void teleport(Location location, TeleportCause reason) {
super.teleport(location, reason); super.teleport(location, reason);
if (!isSpawned())
return;
Location npcLoc = getEntity().getLocation(CACHE_LOCATION); Location npcLoc = getEntity().getLocation(CACHE_LOCATION);
if (isSpawned() && npcLoc.getWorld() == location.getWorld() && npcLoc.distanceSquared(location) < 1) { if (isSpawned() && npcLoc.getWorld() == location.getWorld() && npcLoc.distanceSquared(location) < 1) {
NMS.setHeadYaw(getEntity(), location.getYaw()); NMS.setHeadYaw(getEntity(), location.getYaw());