mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-24 18:18:58 +01:00
Add linear waypoint cycling
This commit is contained in:
parent
67510c43a5
commit
daa4d3cc25
@ -55,6 +55,8 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
@Persist
|
||||
private boolean cachePaths = Setting.DEFAULT_CACHE_WAYPOINT_PATHS.asBoolean();
|
||||
private LinearWaypointGoal currentGoal;
|
||||
@Persist
|
||||
private boolean cycle = false;
|
||||
private NPC npc;
|
||||
private final List<Waypoint> waypoints = Lists.newArrayList();
|
||||
|
||||
@ -287,6 +289,14 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
togglePath();
|
||||
}
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("cycle")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cycle = !cycle;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,6 +404,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
}
|
||||
|
||||
private class LinearWaypointGoal implements Goal {
|
||||
private boolean ascending = true;
|
||||
private final Location cachedLocation = new Location(null, 0, 0, 0);
|
||||
private Waypoint currentDestination;
|
||||
private Iterator<Waypoint> itr;
|
||||
@ -421,6 +432,29 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
}
|
||||
|
||||
private Iterator<Waypoint> getUnsafeIterator() {
|
||||
if (cycle && ascending) {
|
||||
ascending = false;
|
||||
return new Iterator<Waypoint>() {
|
||||
int idx = waypoints.size() - 1;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return idx >= 0 && idx < waypoints.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Waypoint next() {
|
||||
System.out.println(idx);
|
||||
return waypoints.get(idx--);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
waypoints.remove(Math.max(0, idx - 1));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
ascending = true;
|
||||
return new Iterator<Waypoint>() {
|
||||
int idx = 0;
|
||||
|
||||
@ -431,6 +465,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
|
||||
@Override
|
||||
public Waypoint next() {
|
||||
System.out.println(idx);
|
||||
return waypoints.get(idx++);
|
||||
}
|
||||
|
||||
@ -440,6 +475,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
|
Loading…
Reference in New Issue
Block a user