mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-16 20:31:30 +01:00
Use unsafe iteration for waypoints
This commit is contained in:
parent
2d2bc69e1d
commit
4ccce99ad1
@ -365,9 +365,10 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
|
||||
private void ensureItr() {
|
||||
if (itr == null) {
|
||||
itr = waypoints.iterator();
|
||||
} else if (!itr.hasNext())
|
||||
itr = getUnsafeIterator();
|
||||
} else if (!itr.hasNext()) {
|
||||
itr = getNewIterator();
|
||||
}
|
||||
}
|
||||
|
||||
private Navigator getNavigator() {
|
||||
@ -376,18 +377,39 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
|
||||
private Iterator<Waypoint> getNewIterator() {
|
||||
LinearWaypointsCompleteEvent event = new LinearWaypointsCompleteEvent(LinearWaypointProvider.this,
|
||||
waypoints.iterator());
|
||||
getUnsafeIterator());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
Iterator<Waypoint> next = event.getNextWaypoints();
|
||||
return next;
|
||||
}
|
||||
|
||||
private Iterator<Waypoint> getUnsafeIterator() {
|
||||
return new Iterator<Waypoint>() {
|
||||
int idx = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return idx < waypoints.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Waypoint next() {
|
||||
return waypoints.get(idx++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
waypoints.remove(Math.max(0, idx - 1));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
public void onProviderChanged() {
|
||||
itr = waypoints.iterator();
|
||||
itr = getUnsafeIterator();
|
||||
if (currentDestination != null) {
|
||||
if (selector != null) {
|
||||
selector.finish();
|
||||
|
Loading…
Reference in New Issue
Block a user