mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 06:33:56 +01:00
Fix some bugs
This commit is contained in:
parent
816545cf59
commit
f89aac853d
@ -79,6 +79,13 @@ public class CitizensAI implements AI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
executing = new MoveStrategy(npc, destination);
|
executing = new MoveStrategy(npc, destination);
|
||||||
|
Iterator<WeakReference<NavigationCallback>> itr = callbacks.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
NavigationCallback next = itr.next().get();
|
||||||
|
if (next == null || next.onBegin(this)) {
|
||||||
|
itr.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -114,6 +121,7 @@ public class CitizensAI implements AI {
|
|||||||
if (paused)
|
if (paused)
|
||||||
return;
|
return;
|
||||||
if (executing != null && executing.update()) {
|
if (executing != null && executing.update()) {
|
||||||
|
Messaging.log("finished");
|
||||||
Iterator<WeakReference<NavigationCallback>> itr = callbacks.iterator();
|
Iterator<WeakReference<NavigationCallback>> itr = callbacks.iterator();
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
NavigationCallback next = itr.next().get();
|
NavigationCallback next = itr.next().get();
|
||||||
|
@ -19,7 +19,7 @@ public class MoveStrategy implements PathStrategy {
|
|||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
public MoveStrategy(CitizensNPC handle, Location destination) {
|
public MoveStrategy(CitizensNPC handle, Location destination) {
|
||||||
this.handle = (EntityLiving) handle.getHandle();
|
this.handle = handle.getHandle();
|
||||||
this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(),
|
this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(),
|
||||||
destination.getBlockZ(), 16F);
|
destination.getBlockZ(), 16F);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,12 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void end() {
|
public void end() {
|
||||||
player.sendMessage(ChatColor.GREEN + "Exited linear waypoint editor.");
|
player.sendMessage(ChatColor.GREEN + "Exited linear waypoint editor.");
|
||||||
|
if (waypoints.size() == 0)
|
||||||
|
callback.currentIndex = -1;
|
||||||
|
else if (callback.ai != null && callback.currentIndex == -1) {
|
||||||
|
callback.currentIndex = 0;
|
||||||
|
callback.ai.setDestination(waypoints.get(0).getLocation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -39,6 +45,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!event.getPlayer().equals(player))
|
if (!event.getPlayer().equals(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
waypoints.add(new Waypoint(event.getClickedBlock().getLocation()));
|
waypoints.add(new Waypoint(event.getClickedBlock().getLocation()));
|
||||||
Messaging.send(player, "<e>Added<a> a waypoint.");
|
Messaging.send(player, "<e>Added<a> a waypoint.");
|
||||||
@ -47,10 +54,6 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
Messaging.send(player,
|
Messaging.send(player,
|
||||||
String.format("<e>Removed<a> a waypoint (<e>%d<a> remaining)", waypoints.size()));
|
String.format("<e>Removed<a> a waypoint (<e>%d<a> remaining)", waypoints.size()));
|
||||||
}
|
}
|
||||||
if (waypoints.size() == 0)
|
|
||||||
callback.currentIndex = -1;
|
|
||||||
else if (callback.currentIndex == -1)
|
|
||||||
callback.currentIndex = 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -79,7 +82,8 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
|
|
||||||
private class LinearNavigationCallback extends NavigationCallback {
|
private class LinearNavigationCallback extends NavigationCallback {
|
||||||
private boolean executing;
|
private boolean executing;
|
||||||
private int currentIndex;
|
private int currentIndex = -1;
|
||||||
|
private AI ai;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCancel(AI ai, PathCancelReason reason) {
|
public boolean onCancel(AI ai, PathCancelReason reason) {
|
||||||
@ -98,6 +102,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(AI ai) {
|
public void onAttach(AI ai) {
|
||||||
|
this.ai = ai;
|
||||||
executing = false;
|
executing = false;
|
||||||
currentIndex = -1;
|
currentIndex = -1;
|
||||||
cycle();
|
cycle();
|
||||||
|
@ -19,6 +19,7 @@ public class Waypoints extends Trait {
|
|||||||
|
|
||||||
public Waypoints(NPC npc) {
|
public Waypoints(NPC npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
|
npc.getAI().registerNavigationCallback(provider.getCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user