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
|
@Persist
|
||||||
private boolean cachePaths = Setting.DEFAULT_CACHE_WAYPOINT_PATHS.asBoolean();
|
private boolean cachePaths = Setting.DEFAULT_CACHE_WAYPOINT_PATHS.asBoolean();
|
||||||
private LinearWaypointGoal currentGoal;
|
private LinearWaypointGoal currentGoal;
|
||||||
|
@Persist
|
||||||
|
private boolean cycle = false;
|
||||||
private NPC npc;
|
private NPC npc;
|
||||||
private final List<Waypoint> waypoints = Lists.newArrayList();
|
private final List<Waypoint> waypoints = Lists.newArrayList();
|
||||||
|
|
||||||
@ -287,6 +289,14 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
|||||||
togglePath();
|
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 class LinearWaypointGoal implements Goal {
|
||||||
|
private boolean ascending = true;
|
||||||
private final Location cachedLocation = new Location(null, 0, 0, 0);
|
private final Location cachedLocation = new Location(null, 0, 0, 0);
|
||||||
private Waypoint currentDestination;
|
private Waypoint currentDestination;
|
||||||
private Iterator<Waypoint> itr;
|
private Iterator<Waypoint> itr;
|
||||||
@ -421,24 +432,49 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Iterator<Waypoint> getUnsafeIterator() {
|
private Iterator<Waypoint> getUnsafeIterator() {
|
||||||
return new Iterator<Waypoint>() {
|
if (cycle && ascending) {
|
||||||
int idx = 0;
|
ascending = false;
|
||||||
|
return new Iterator<Waypoint>() {
|
||||||
|
int idx = waypoints.size() - 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return idx < waypoints.size();
|
return idx >= 0 && idx < waypoints.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Waypoint next() {
|
public Waypoint next() {
|
||||||
return waypoints.get(idx++);
|
System.out.println(idx);
|
||||||
}
|
return waypoints.get(idx--);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
waypoints.remove(Math.max(0, idx - 1));
|
waypoints.remove(Math.max(0, idx - 1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
ascending = true;
|
||||||
|
return new Iterator<Waypoint>() {
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return 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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPaused() {
|
public boolean isPaused() {
|
||||||
|
Loading…
Reference in New Issue
Block a user