Allow flying NPCs to have their path set via command

This commit is contained in:
fullwall 2013-12-01 18:45:10 +08:00
parent 3c9b42355f
commit 3896c67709
3 changed files with 17 additions and 8 deletions

View File

@ -10,7 +10,6 @@ import net.citizensnpcs.editor.EquipmentEditor;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@Requirements(selected = true, ownership = true)
@ -48,8 +47,7 @@ public class EditorCommands {
max = 1,
flags = "*",
permission = "citizens.npc.edit.path")
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BLAZE, EntityType.ENDER_DRAGON,
EntityType.GHAST, EntityType.BAT, EntityType.WITHER, EntityType.SQUID })
@Requirements(selected = true, ownership = true)
public void path(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player, args));
}

View File

@ -86,6 +86,7 @@ public class CitizensNavigator implements Navigator, Runnable {
return executing != null;
}
@Override
public boolean isPaused() {
return paused;
}
@ -126,8 +127,9 @@ public class CitizensNavigator implements Navigator, Runnable {
NavigationCompleteEvent event = new NavigationCompleteEvent(this);
PathStrategy old = executing;
Bukkit.getPluginManager().callEvent(event);
if (old == executing)
if (old == executing) {
stopNavigating(null);
}
}
}
@ -139,6 +141,7 @@ public class CitizensNavigator implements Navigator, Runnable {
root.setBoolean("usedefaultstuckaction", defaultParams.stuckAction() == TeleportStuckAction.INSTANCE);
}
@Override
public void setPaused(boolean paused) {
this.paused = paused;
}

View File

@ -134,13 +134,15 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private class AStarTargeter implements TargetNavigator {
private int failureTimes = 0;
private AStarNavigationStrategy strategy = new AStarNavigationStrategy(npc, target.getBukkitEntity()
.getLocation(TARGET_LOCATION), parameters);
private PathStrategy strategy;
public AStarTargeter() {
setStrategy();
}
@Override
public void setPath() {
strategy = new AStarNavigationStrategy(npc, target.getBukkitEntity().getLocation(TARGET_LOCATION),
parameters);
setStrategy();
strategy.update();
CancelReason subReason = strategy.getCancelReason();
if (subReason == CancelReason.STUCK) {
@ -153,6 +155,12 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
}
}
private void setStrategy() {
Location location = target.getBukkitEntity().getLocation(TARGET_LOCATION);
strategy = npc.isFlyable() ? new FlyingAStarNavigationStrategy(npc, location, parameters)
: new AStarNavigationStrategy(npc, location, parameters);
}
@Override
public void stop() {
strategy.stop();