mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 11:05:49 +01:00
Add isPaused() and setPaused(boolean) to WaypointProvider
This commit is contained in:
parent
af9c42cfb6
commit
f27eab8622
@ -108,6 +108,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaused() {
|
||||
return currentGoal.isPaused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Waypoint> iterator() {
|
||||
return waypoints.iterator();
|
||||
@ -148,4 +153,9 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
root.setDouble("pitch", location.getPitch());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaused(boolean paused) {
|
||||
currentGoal.setPaused(paused);
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ public class WaypointGoal implements Goal {
|
||||
private Location currentDestination;
|
||||
private Iterator<Waypoint> itr;
|
||||
private final Navigator navigator;
|
||||
private boolean paused;
|
||||
private final Iterable<Waypoint> 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();
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user