mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-01 04:51:32 +01:00
Add isPaused() and setPaused(boolean) to WaypointProvider
This commit is contained in:
parent
54c80aaa08
commit
4294758937
@ -108,6 +108,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPaused() {
|
||||||
|
return currentGoal.isPaused();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Waypoint> iterator() {
|
public Iterator<Waypoint> iterator() {
|
||||||
return waypoints.iterator();
|
return waypoints.iterator();
|
||||||
@ -148,4 +153,9 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
|||||||
root.setDouble("pitch", location.getPitch());
|
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 Location currentDestination;
|
||||||
private Iterator<Waypoint> itr;
|
private Iterator<Waypoint> itr;
|
||||||
private final Navigator navigator;
|
private final Navigator navigator;
|
||||||
|
private boolean paused;
|
||||||
private final Iterable<Waypoint> provider;
|
private final Iterable<Waypoint> provider;
|
||||||
private GoalSelector selector;
|
private GoalSelector selector;
|
||||||
|
|
||||||
@ -29,6 +30,10 @@ public class WaypointGoal implements Goal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPaused() {
|
||||||
|
return paused;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onNavigationCancel(NavigationCancelEvent event) {
|
public void onNavigationCancel(NavigationCancelEvent event) {
|
||||||
if (currentDestination == null || !event.getNavigator().equals(navigator))
|
if (currentDestination == null || !event.getNavigator().equals(navigator))
|
||||||
@ -61,10 +66,18 @@ public class WaypointGoal implements Goal {
|
|||||||
public void run() {
|
public void run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPaused(boolean paused) {
|
||||||
|
if (paused && currentDestination != null)
|
||||||
|
selector.finish();
|
||||||
|
this.paused = paused;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldExecute(GoalSelector selector) {
|
public boolean shouldExecute(GoalSelector selector) {
|
||||||
|
if (paused || currentDestination != null)
|
||||||
|
return false;
|
||||||
ensureItr();
|
ensureItr();
|
||||||
boolean shouldExecute = currentDestination == null && itr.hasNext();
|
boolean shouldExecute = itr.hasNext();
|
||||||
if (shouldExecute) {
|
if (shouldExecute) {
|
||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
currentDestination = itr.next().getLocation();
|
currentDestination = itr.next().getLocation();
|
||||||
|
@ -17,6 +17,13 @@ public interface WaypointProvider {
|
|||||||
*/
|
*/
|
||||||
public Editor createEditor(Player player);
|
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}.
|
* Loads from the specified {@link DataKey}.
|
||||||
*
|
*
|
||||||
@ -25,6 +32,12 @@ public interface WaypointProvider {
|
|||||||
*/
|
*/
|
||||||
public void load(DataKey key);
|
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);
|
public void onSpawn(NPC npc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,4 +47,12 @@ public interface WaypointProvider {
|
|||||||
* The key to save to
|
* The key to save to
|
||||||
*/
|
*/
|
||||||
public void save(DataKey key);
|
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) {
|
public Editor getEditor(Player player) {
|
||||||
return provider.createEditor(player);
|
return provider.createEditor(player);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user