Search in sources :

Example 1 with NavigationCompleteEvent

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);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PathStrategy(net.citizensnpcs.api.ai.PathStrategy) NavigationCompleteEvent(net.citizensnpcs.api.ai.event.NavigationCompleteEvent) Location(org.bukkit.Location)

Aggregations

PathStrategy (net.citizensnpcs.api.ai.PathStrategy)1 NavigationCompleteEvent (net.citizensnpcs.api.ai.event.NavigationCompleteEvent)1 Location (org.bukkit.Location)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1