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.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints; import net.citizensnpcs.trait.waypoint.Waypoints;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@Requirements(selected = true, ownership = true) @Requirements(selected = true, ownership = true)
@ -48,8 +47,7 @@ public class EditorCommands {
max = 1, max = 1,
flags = "*", flags = "*",
permission = "citizens.npc.edit.path") permission = "citizens.npc.edit.path")
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BLAZE, EntityType.ENDER_DRAGON, @Requirements(selected = true, ownership = true)
EntityType.GHAST, EntityType.BAT, EntityType.WITHER, EntityType.SQUID })
public void path(CommandContext args, Player player, NPC npc) { public void path(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player, args)); 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; return executing != null;
} }
@Override
public boolean isPaused() { public boolean isPaused() {
return paused; return paused;
} }
@ -126,8 +127,9 @@ public class CitizensNavigator implements Navigator, Runnable {
NavigationCompleteEvent event = new NavigationCompleteEvent(this); NavigationCompleteEvent event = new NavigationCompleteEvent(this);
PathStrategy old = executing; PathStrategy old = executing;
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (old == executing) if (old == executing) {
stopNavigating(null); stopNavigating(null);
}
} }
} }
@ -139,6 +141,7 @@ public class CitizensNavigator implements Navigator, Runnable {
root.setBoolean("usedefaultstuckaction", defaultParams.stuckAction() == TeleportStuckAction.INSTANCE); root.setBoolean("usedefaultstuckaction", defaultParams.stuckAction() == TeleportStuckAction.INSTANCE);
} }
@Override
public void setPaused(boolean paused) { public void setPaused(boolean paused) {
this.paused = paused; this.paused = paused;
} }

View File

@ -134,13 +134,15 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private class AStarTargeter implements TargetNavigator { private class AStarTargeter implements TargetNavigator {
private int failureTimes = 0; private int failureTimes = 0;
private AStarNavigationStrategy strategy = new AStarNavigationStrategy(npc, target.getBukkitEntity() private PathStrategy strategy;
.getLocation(TARGET_LOCATION), parameters);
public AStarTargeter() {
setStrategy();
}
@Override @Override
public void setPath() { public void setPath() {
strategy = new AStarNavigationStrategy(npc, target.getBukkitEntity().getLocation(TARGET_LOCATION), setStrategy();
parameters);
strategy.update(); strategy.update();
CancelReason subReason = strategy.getCancelReason(); CancelReason subReason = strategy.getCancelReason();
if (subReason == CancelReason.STUCK) { 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 @Override
public void stop() { public void stop() {
strategy.stop(); strategy.stop();