use of net.citizensnpcs.api.ai.event.NavigatorCallback in project CitizensAPI by CitizensDev.
the class TargetNearbyEntityGoal method shouldExecute.
@Override
public boolean shouldExecute() {
if (targets.size() == 0 || !npc.isSpawned())
return false;
Collection<Entity> nearby = npc.getEntity().getNearbyEntities(radius, radius, radius);
this.target = null;
for (Entity entity : nearby) {
if (targets.contains(entity.getType())) {
target = entity;
break;
}
}
if (target != null) {
npc.getNavigator().setTarget(target, aggressive);
npc.getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
@Override
public void onCompletion(CancelReason cancelReason) {
reason = cancelReason;
finished = true;
}
});
return true;
}
return false;
}
use of net.citizensnpcs.api.ai.event.NavigatorCallback in project CitizensAPI by CitizensDev.
the class MoveToGoal method shouldExecute.
@Override
public boolean shouldExecute() {
boolean executing = !npc.getNavigator().isNavigating() && target != null;
if (executing) {
npc.getNavigator().setTarget(target);
npc.getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
@Override
public void onCompletion(CancelReason cancelReason) {
finished = true;
reason = cancelReason;
}
});
}
return executing;
}
use of net.citizensnpcs.api.ai.event.NavigatorCallback 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