use of net.citizensnpcs.api.ai.StuckAction 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();
}
}
Aggregations