mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
Add LinearWaypointsCompleteEvent
This commit is contained in:
parent
6f1eb32445
commit
871259dcff
@ -322,8 +322,18 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
private GoalSelector selector;
|
||||
|
||||
private void ensureItr() {
|
||||
if (itr == null || !itr.hasNext())
|
||||
if (itr == null)
|
||||
itr = waypoints.iterator();
|
||||
else if (!itr.hasNext())
|
||||
itr = getNewIterator();
|
||||
}
|
||||
|
||||
private Iterator<Waypoint> getNewIterator() {
|
||||
LinearWaypointsCompleteEvent event = new LinearWaypointsCompleteEvent(
|
||||
LinearWaypointProvider.this, waypoints.iterator());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
Iterator<Waypoint> next = event.getNextWaypoints();
|
||||
return next;
|
||||
}
|
||||
|
||||
private Navigator getNavigator() {
|
||||
@ -375,24 +385,20 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute(GoalSelector selector) {
|
||||
if (paused || currentDestination != null || !npc.isSpawned() || getNavigator().isNavigating()
|
||||
|| waypoints.size() == 0) {
|
||||
if (paused || currentDestination != null || !npc.isSpawned() || getNavigator().isNavigating()) {
|
||||
return false;
|
||||
}
|
||||
if (waypoints.size() == 1) {
|
||||
// avoid pathing to the same point repeatedly
|
||||
Location dest = npc.getBukkitEntity().getLocation();
|
||||
if (waypoints.get(0).getLocation().distanceSquared(dest) < 3)
|
||||
return false;
|
||||
}
|
||||
ensureItr();
|
||||
boolean shouldExecute = itr.hasNext();
|
||||
if (shouldExecute) {
|
||||
this.selector = selector;
|
||||
currentDestination = itr.next();
|
||||
getNavigator().setTarget(currentDestination.getLocation());
|
||||
}
|
||||
return shouldExecute;
|
||||
if (!shouldExecute)
|
||||
return false;
|
||||
this.selector = selector;
|
||||
Waypoint next = itr.next();
|
||||
if (npc.getBukkitEntity().getLocation().distanceSquared(next.getLocation()) < 3)
|
||||
return false;
|
||||
currentDestination = next;
|
||||
getNavigator().setTarget(currentDestination.getLocation());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.citizensnpcs.api.event.CitizensEvent;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class LinearWaypointsCompleteEvent extends CitizensEvent {
|
||||
private Iterator<Waypoint> next;
|
||||
private final WaypointProvider provider;
|
||||
|
||||
public LinearWaypointsCompleteEvent(WaypointProvider provider, Iterator<Waypoint> next) {
|
||||
this.next = next;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public WaypointProvider getWaypointProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public Iterator<Waypoint> getNextWaypoints() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void setNextWaypoints(Iterator<Waypoint> waypoints) {
|
||||
this.next = waypoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
}
|
Loading…
Reference in New Issue
Block a user