@Override public void run() { CitizensConversation conv = (CitizensConversation) event.getConversation(); NPC npc = conv.getNPC(); if (!npcs.containsKey(npc)) { Navigator nav = npc.getNavigator(); npcs.put(npc, 1); locs.put(npc, nav.getTargetAsLocation()); nav.setPaused(true); nav.cancelNavigation(); nav.setTarget(conv.getNPC().getEntity().getLocation()); nav.setPaused(true); nav.cancelNavigation(); } else { npcs.put(npc, npcs.get(npc) + 1); } } }.runTask(BetonQuest.getInstance());
@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; } }
/** * Causes the NPC to immediately path over to a position. */ public void pathTo(Location target) { pauseWaypoints(); pathingTo = target; npc.getNavigator().getDefaultParameters().distanceMargin(1.5); getNPC().getNavigator().setTarget(target); chasing = null; needsSafeReturn = true; }
@Override public void run() { CitizensConversation conv = (CitizensConversation) event.getConversation(); NPC npc = conv.getNPC(); Integer i = npcs.get(npc); i--; if (i == 0) { npcs.remove(npc); if (npc.isSpawned()) { Navigator nav = npc.getNavigator(); nav.setPaused(false); nav.setTarget(locs.remove(npc)); } } else { npcs.put(npc, i); } } }.runTask(BetonQuest.getInstance());
if (getNPC().getNavigator().getTargetType() == TargetType.LOCATION && getNPC().getNavigator().getTargetAsLocation() != null && ((getNPC().getNavigator().getTargetAsLocation().getWorld().equals(entity.getWorld()) && getNPC().getNavigator().getTargetAsLocation().distanceSquared(entity.getLocation()) < 2 * 2))) { return; sentinel.chased = true; sentinel.needsSafeReturn = true; if (getNPC().getNavigator().getTargetType() == TargetType.ENTITY && SentinelUtilities.getTargetFor(getNPC().getNavigator().getEntityTarget()).getUniqueId().equals(entity.getUniqueId())) { return; getNPC().getNavigator().getDefaultParameters().stuckAction(null); getNPC().getNavigator().setTarget(entity.getLocation()); getNPC().getNavigator().setTarget(entity, false); getNPC().getNavigator().getLocalParameters().speedModifier((float) sentinel.speed);
if (!npc.getNavigator().isNavigating()) { pathingTo = null; if (ticksCountGuard >= 30) { ticksCountGuard = 0; npc.getNavigator().getDefaultParameters().distanceMargin(SentinelPlugin.instance.guardDistanceMargin); npc.getNavigator().getDefaultParameters().range(100); npc.getNavigator().getDefaultParameters().stuckAction(TeleportStuckAction.INSTANCE); npc.getNavigator().setTarget(SentinelUtilities.pickNear(player.getLocation(), SentinelPlugin.instance.guardDistanceSelectionRange)); npc.getNavigator().getLocalParameters().speedModifier((float) speed); chased = true; npc.getNavigator().getDefaultParameters().stuckAction(TeleportStuckAction.INSTANCE); npc.getNavigator().setTarget(near); npc.getNavigator().getLocalParameters().speedModifier((float) speed); needsSafeReturn = false; chased = false; if (pathingTo == null && npc.getNavigator().isNavigating()) { npc.getNavigator().cancelNavigation(); needsSafeReturn = false; else if (chasing == null && pathingTo == null && npc.getNavigator().isNavigating() && needsSafeReturn) { npc.getNavigator().cancelNavigation(); needsSafeReturn = false;
@Override public void reset() { npc.getNavigator().cancelNavigation(); reason = null; finished = false; }
@Override public boolean shouldExecute() { if (!npc.isSpawned() || npc.getNavigator().isNavigating() || paused) return false; Location dest = findRandomPosition(); if (dest == null) return false; npc.getNavigator().setTarget(dest); CitizensAPI.registerEvents(this); return true; }
@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; }
CitizensWalkingListener.getInstance().setNewTargetLocation(npc, firstLocation.getLocation(playerID)); } else { npc.getNavigator().setTarget(firstLocation.getLocation(playerID));
@Override public boolean run(NPC npc, Navigator navigator) { if (!npc.isSpawned()) return false; Location base = navigator.getTargetAsLocation(); if (base == null || npc.getEntity().getWorld() == base.getWorld() && npc.getEntity().getLocation(CACHE_LOC).distanceSquared(base) <= RANGE) return true; Block block = base.getBlock(); int iterations = 0; while (!canStand(block)) { if (iterations++ >= MAX_ITERATIONS) { block = base.getBlock(); break; } block = block.getRelative(BlockFace.UP); } npc.teleport(block.getLocation(), TeleportCause.PLUGIN); return false; }
@Override public BehaviorStatus run() { if (!npc.getNavigator().isNavigating() || forceFinish) return BehaviorStatus.SUCCESS; return BehaviorStatus.RUNNING; }
@Override public void run(final NPC npc, Block point, ListIterator<Block> path) { current = path; if (added || npc.data().<Boolean> get("running-ladder", false)) { added = true; return; } Runnable callback = new Runnable() { Location dummy = new Location(null, 0, 0, 0); @Override public void run() { if (npc.getEntity().getLocation(dummy).getBlock().getType() == Material.LADDER && current.next().getY() > current.previous().getY()) { npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0.3)); } } }; npc.getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() { @Override public void onCompletion(CancelReason cancelReason) { npc.data().set("running-ladder", false); } }); npc.getNavigator().getLocalParameters().addRunCallback(callback); added = true; } }
/** * @return The {@link NPC} involved in this event */ public NPC getNPC() { return navigator.getNPC(); } }
@Override public void reset() { npc.getNavigator().cancelNavigation(); target = null; finished = false; reason = null; }
CitizensWalkingListener.getInstance().setNewTargetLocation(npc, next); } else { npc.getNavigator().setTarget(next); npc.getNavigator().setTarget(locationsIterator.previous().getLocation(currentPlayer)); } catch (QuestRuntimeException e) { Debug.error("Error while finishing NPC " + npc.getId() + " navigation: " + e.getMessage()); npc.getNavigator().setPaused(true); new BukkitRunnable() { @Override
@Override public Collection<NPC> getNearby(NPC npc) { if (cached != null && cacheTicks++ < maxCacheTicks) { return cached; } else { cached = null; cacheTicks = 0; } Collection<NPC> ret = Lists.newArrayList(); for (Entity entity : npc.getEntity().getNearbyEntities(radius, radius, radius)) { NPC npc2 = CitizensAPI.getNPCRegistry().getNPC(entity); if (npc2 != null) { if (!npc2.getNavigator().isNavigating()) continue; ret.add(npc2); } } this.cached = ret; return ret; } }
if (!currentTargets.contains(cte)) { sentinel.chasing = null; getNPC().getNavigator().cancelNavigation();
if (!pos.getWorld().equals(getLivingEntity().getWorld())) { getNPC().getNavigator().cancelNavigation(); getLivingEntity().teleport(sentinel.getGuardZone()); return null;
if (!pos.getWorld().equals(getLivingEntity().getWorld())) { getNPC().getNavigator().cancelNavigation(); getLivingEntity().teleport(sentinel.getGuardZone()); return null;