use of net.citizensnpcs.api.ai.event.NavigationCompleteEvent in project Citizens2 by CitizensDev.
the class CitizensNavigator method run.
@Override
public void run() {
updateMountedStatus();
if (!isNavigating() || !npc.isSpawned() || paused)
return;
if (!npc.getStoredLocation().getWorld().equals(getTargetAsLocation().getWorld()) || Math.pow(localParams.range(), 2) < npc.getStoredLocation().distanceSquared(getTargetAsLocation())) {
stopNavigating(CancelReason.STUCK);
return;
}
if (updateStationaryStatus())
return;
updatePathfindingRange();
boolean finished = executing.update();
if (localParams.lookAtFunction() != null) {
Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, true);
Entity entity = npc.getEntity().getPassenger();
Location npcLoc = npc.getEntity().getLocation();
while (entity != null) {
Location loc = entity.getLocation(STATIONARY_LOCATION);
loc.setYaw(npcLoc.getYaw());
entity.teleport(loc);
entity = entity.getPassenger();
}
}
if (!finished) {
return;
}
if (executing.getCancelReason() != null) {
stopNavigating(executing.getCancelReason());
} else {
NavigationCompleteEvent event = new NavigationCompleteEvent(this);
PathStrategy old = executing;
Bukkit.getPluginManager().callEvent(event);
if (old == executing) {
stopNavigating(null);
}
}
}
Aggregations