diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java index d94ecb835..3c27a45a7 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java @@ -108,6 +108,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable iterator() { return waypoints.iterator(); @@ -148,4 +153,9 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable itr; private final Navigator navigator; + private boolean paused; private final Iterable provider; private GoalSelector selector; @@ -29,6 +30,10 @@ public class WaypointGoal implements Goal { } } + public boolean isPaused() { + return paused; + } + @EventHandler public void onNavigationCancel(NavigationCancelEvent event) { if (currentDestination == null || !event.getNavigator().equals(navigator)) @@ -61,10 +66,18 @@ public class WaypointGoal implements Goal { public void run() { } + public void setPaused(boolean paused) { + if (paused && currentDestination != null) + selector.finish(); + this.paused = paused; + } + @Override public boolean shouldExecute(GoalSelector selector) { + if (paused || currentDestination != null) + return false; ensureItr(); - boolean shouldExecute = currentDestination == null && itr.hasNext(); + boolean shouldExecute = itr.hasNext(); if (shouldExecute) { this.selector = selector; currentDestination = itr.next().getLocation(); diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java index 39393cf75..e0b5d4b68 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java @@ -17,6 +17,13 @@ public interface WaypointProvider { */ public Editor createEditor(Player player); + /** + * Returns whether this provider has paused execution of waypoints. + * + * @return Whether the provider is paused. + */ + public boolean isPaused(); + /** * Loads from the specified {@link DataKey}. * @@ -25,6 +32,12 @@ public interface WaypointProvider { */ public void load(DataKey key); + /** + * Called when the {@link NPC} attached to this provider is spawned. + * + * @param npc + * The attached NPC + */ public void onSpawn(NPC npc); /** @@ -34,4 +47,12 @@ public interface WaypointProvider { * The key to save to */ public void save(DataKey key); + + /** + * Pauses waypoint execution. + * + * @param paused + * Whether to pause waypoint execution. + */ + public void setPaused(boolean paused); } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java b/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java index e69c59f82..95dba5b51 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java @@ -29,6 +29,16 @@ public class Waypoints extends Trait { } } + /** + * Returns the current {@link WaypointProvider}. May be null during + * initialisation. + * + * @return The current provider + */ + public WaypointProvider getCurrentProvider() { + return provider; + } + public Editor getEditor(Player player) { return provider.createEditor(player); }