From 338a853b791d8ceb0f566fa61f18b15d09a637b7 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 9 Sep 2012 18:47:25 +0800 Subject: [PATCH] Fix some issues with Navigator as reported by jrbudda --- .../npc/ai/CitizensNavigator.java | 20 +++++++++++++------ .../npc/ai/MCNavigationStrategy.java | 5 +++++ .../citizensnpcs/npc/ai/MCTargetStrategy.java | 6 +++++- .../net/citizensnpcs/npc/ai/PathStrategy.java | 2 ++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 049c35e46..35d932970 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -149,13 +149,18 @@ public class CitizensNavigator implements Navigator { StuckAction action = localParams.stuckAction(); if (action != null) { boolean shouldContinue = action.run(npc, this); - if (shouldContinue) + if (shouldContinue) { + stationaryTicks = 0; + executing.clearCancelReason(); return; + } } - stationaryTicks = 0; } - Bukkit.getPluginManager().callEvent(new NavigationCancelEvent(this, reason)); - stopNavigating(); + NavigationCancelEvent event = new NavigationCancelEvent(this, reason); + PathStrategy old = executing; + Bukkit.getPluginManager().callEvent(event); + if (old == executing) + stopNavigating(); } private void switchStrategyTo(PathStrategy newStrategy) { @@ -175,8 +180,11 @@ public class CitizensNavigator implements Navigator { if (executing.getCancelReason() != null) stopNavigating(executing.getCancelReason()); else { - Bukkit.getPluginManager().callEvent(new NavigationCompleteEvent(this)); - stopNavigating(); + NavigationCompleteEvent event = new NavigationCompleteEvent(this); + PathStrategy old = executing; + Bukkit.getPluginManager().callEvent(event); + if (old == executing) + stopNavigating(); } } diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java index dcc4bf1a1..71e18b5e1 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java @@ -59,4 +59,9 @@ public class MCNavigationStrategy implements PathStrategy { navigation.a(parameters.speed()); return navigation.f(); } + + @Override + public void clearCancelReason() { + cancelReason = null; + } } diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 36eda0333..452a64aad 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -101,7 +101,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { return false; } - private static final int ATTACK_DELAY_TICKS = 20; + @Override + public void clearCancelReason() { + cancelReason = null; + } + private static final int ATTACK_DELAY_TICKS = 20; private static final double ATTACK_DISTANCE = 1.75 * 1.75; } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java index 9e49a04ef..72ad99637 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java @@ -15,4 +15,6 @@ public interface PathStrategy { void stop(); boolean update(); + + void clearCancelReason(); } \ No newline at end of file