Search in sources :

Example 1 with NavigationStuckEvent

use of net.citizensnpcs.api.ai.event.NavigationStuckEvent in project Citizens2 by CitizensDev.

the class CitizensNavigator method stopNavigating.

private void stopNavigating(CancelReason reason) {
    if (!isNavigating())
        return;
    Iterator<NavigatorCallback> itr = localParams.callbacks().iterator();
    while (itr.hasNext()) {
        itr.next().onCompletion(reason);
        itr.remove();
    }
    if (reason == null) {
        stopNavigating();
        return;
    }
    if (reason == CancelReason.STUCK) {
        StuckAction action = localParams.stuckAction();
        NavigationStuckEvent event = new NavigationStuckEvent(this, action);
        Bukkit.getPluginManager().callEvent(event);
        action = event.getAction();
        boolean shouldContinue = action != null ? action.run(npc, this) : false;
        if (shouldContinue) {
            stationaryTicks = 0;
            executing.clearCancelReason();
            return;
        }
    }
    NavigationCancelEvent event = new NavigationCancelEvent(this, reason);
    PathStrategy old = executing;
    Bukkit.getPluginManager().callEvent(event);
    if (old == executing) {
        stopNavigating();
    }
}
Also used : NavigationStuckEvent(net.citizensnpcs.api.ai.event.NavigationStuckEvent) PathStrategy(net.citizensnpcs.api.ai.PathStrategy) TeleportStuckAction(net.citizensnpcs.api.ai.TeleportStuckAction) StuckAction(net.citizensnpcs.api.ai.StuckAction) NavigationCancelEvent(net.citizensnpcs.api.ai.event.NavigationCancelEvent) NavigatorCallback(net.citizensnpcs.api.ai.event.NavigatorCallback)

Aggregations

PathStrategy (net.citizensnpcs.api.ai.PathStrategy)1 StuckAction (net.citizensnpcs.api.ai.StuckAction)1 TeleportStuckAction (net.citizensnpcs.api.ai.TeleportStuckAction)1 NavigationCancelEvent (net.citizensnpcs.api.ai.event.NavigationCancelEvent)1 NavigationStuckEvent (net.citizensnpcs.api.ai.event.NavigationStuckEvent)1 NavigatorCallback (net.citizensnpcs.api.ai.event.NavigatorCallback)1