Citizens2/src/main/java/net/citizensnpcs/trait/waypoint/PassiveWaypointCycler.java

76 lines
1.9 KiB
Java
Raw Normal View History

2012-03-02 11:36:54 +01:00
package net.citizensnpcs.trait.waypoint;
import java.util.Iterator;
import org.bukkit.Location;
2012-07-18 17:42:43 +02:00
public class PassiveWaypointCycler {
private Location dest;
2012-03-02 11:36:54 +01:00
private boolean executing;
private Iterator<Waypoint> itr;
2012-03-02 11:36:54 +01:00
private final Iterable<Waypoint> provider;
2012-07-18 17:42:43 +02:00
public PassiveWaypointCycler(Iterable<Waypoint> provider) {
2012-03-02 11:36:54 +01:00
this.provider = provider;
}
private void ensureItr() {
2012-03-10 06:59:37 +01:00
if (itr == null || !itr.hasNext()) {
2012-03-02 11:36:54 +01:00
itr = provider.iterator();
2012-03-10 06:59:37 +01:00
}
2012-03-02 11:36:54 +01:00
}
2012-07-18 17:42:43 +02:00
/*@Override
public boolean onCancel(AI ai, CancelReason reason) {
2012-06-11 10:11:54 +02:00
if (hackfix) {
hackfix = false;
return false;
}
hackfix = false;
if (executing && reason == CancelReason.REPLACE) {
2012-03-02 11:36:54 +01:00
executing = false;
return false;
}
executing = true;
ensureItr();
if (dest == null && itr.hasNext())
dest = itr.next().getLocation();
if (dest != null) {
2012-06-11 10:11:54 +02:00
hackfix = true;
ai.setDestination(dest);
2012-06-11 10:11:54 +02:00
hackfix = false;
2012-03-02 11:36:54 +01:00
}
return false;
}
@Override
public boolean onCompletion(AI ai) {
if (executing) { // if we're executing, we need to get the next waypoint
ensureItr();
2012-03-02 12:39:47 +01:00
dest = itr.hasNext() ? itr.next().getLocation() : null;
2012-03-02 11:36:54 +01:00
} else {
executing = true;
// we're free to return to our waypoints!
// if we had a destination, we will return to it.
}
if (dest != null) {
ai.setDestination(dest);
}
return false;
}
public void onProviderChanged() {
itr = provider.iterator();
2012-03-25 10:28:47 +02:00
if (ai == null)
return;
2012-03-02 12:20:38 +01:00
dest = itr.hasNext() ? itr.next().getLocation() : null;
2012-03-02 12:39:47 +01:00
if (dest != null) {
ai.setDestination(dest);
}
2012-07-18 17:42:43 +02:00
}*/
public void onProviderChanged() {
2012-03-02 11:36:54 +01:00
}
}