Search in sources :

Example 1 with NavigatorCallback

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

Example 2 with NavigatorCallback

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;
}
Also used : CancelReason(net.citizensnpcs.api.ai.event.CancelReason) NavigatorCallback(net.citizensnpcs.api.ai.event.NavigatorCallback)

Example 3 with NavigatorCallback

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();
    }
}
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

NavigatorCallback (net.citizensnpcs.api.ai.event.NavigatorCallback)3 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)2 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 Entity (org.bukkit.entity.Entity)1