Fix some issues with Navigator as reported by jrbudda

This commit is contained in:
fullwall 2012-09-09 18:47:25 +08:00
parent f62e536473
commit 338a853b79
4 changed files with 26 additions and 7 deletions

View File

@ -149,13 +149,18 @@ public class CitizensNavigator implements Navigator {
StuckAction action = localParams.stuckAction(); StuckAction action = localParams.stuckAction();
if (action != null) { if (action != null) {
boolean shouldContinue = action.run(npc, this); boolean shouldContinue = action.run(npc, this);
if (shouldContinue) if (shouldContinue) {
stationaryTicks = 0;
executing.clearCancelReason();
return; return;
}
} }
stationaryTicks = 0;
} }
Bukkit.getPluginManager().callEvent(new NavigationCancelEvent(this, reason)); NavigationCancelEvent event = new NavigationCancelEvent(this, reason);
stopNavigating(); PathStrategy old = executing;
Bukkit.getPluginManager().callEvent(event);
if (old == executing)
stopNavigating();
} }
private void switchStrategyTo(PathStrategy newStrategy) { private void switchStrategyTo(PathStrategy newStrategy) {
@ -175,8 +180,11 @@ public class CitizensNavigator implements Navigator {
if (executing.getCancelReason() != null) if (executing.getCancelReason() != null)
stopNavigating(executing.getCancelReason()); stopNavigating(executing.getCancelReason());
else { else {
Bukkit.getPluginManager().callEvent(new NavigationCompleteEvent(this)); NavigationCompleteEvent event = new NavigationCompleteEvent(this);
stopNavigating(); PathStrategy old = executing;
Bukkit.getPluginManager().callEvent(event);
if (old == executing)
stopNavigating();
} }
} }

View File

@ -59,4 +59,9 @@ public class MCNavigationStrategy implements PathStrategy {
navigation.a(parameters.speed()); navigation.a(parameters.speed());
return navigation.f(); return navigation.f();
} }
@Override
public void clearCancelReason() {
cancelReason = null;
}
} }

View File

@ -101,7 +101,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
return false; 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; private static final double ATTACK_DISTANCE = 1.75 * 1.75;
} }

View File

@ -15,4 +15,6 @@ public interface PathStrategy {
void stop(); void stop();
boolean update(); boolean update();
void clearCancelReason();
} }