From 2e56b1f5e89e5b0df916590ed612ef1852450094 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 4 Nov 2013 23:42:32 +0800 Subject: [PATCH] Add a new command to set avoiding water while pathfinding --- .../citizensnpcs/commands/NPCCommands.java | 24 ++++++++++++++++--- .../java/net/citizensnpcs/util/Messages.java | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index b0013a915..e3d2d956e 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -190,8 +190,8 @@ public class NPCCommands { paginator.addLine(line); } else { String[] parts = trait.getAnchors().get(i).getUnloadedValue(); - String line = "" + i + " " + trait.getAnchors().get(i).getName() + " " - + parts[0] + " " + parts[1] + ", " + parts[2] + ", " + parts[3] + " (unloaded)"; + String line = "" + i + " " + trait.getAnchors().get(i).getName() + " " + parts[0] + + " " + parts[1] + ", " + parts[2] + ", " + parts[3] + " (unloaded)"; paginator.addLine(line); } } @@ -779,6 +779,24 @@ public class NPCCommands { Messaging.sendTr(sender, serverOwner ? Messages.OWNER_SET_SERVER : Messages.OWNER_SET, npc.getName(), name); } + @Command( + aliases = { "npc" }, + usage = "pathopt --avoid-water|aw [true|false]", + desc = "Sets an NPC's pathfinding options", + modifiers = { "pathopt", "po", "patho" }, + min = 1, + max = 1, + permission = "citizens.npc.pathfindingoptions") + public void pathfindingOptions(CommandContext args, CommandSender sender, NPC npc) { + if (args.hasValueFlag("avoid-water") || args.hasValueFlag("aw")) { + String raw = args.getFlag("avoid-water", args.getFlag("aw")); + boolean avoid = Boolean.parseBoolean(raw); + npc.getNavigator().getDefaultParameters().avoidWater(avoid); + Messaging.sendTr(sender, avoid ? Messages.PATHFINDING_OPTIONS_AVOID_WATER_SET + : Messages.PATHFINDING_OPTIONS_AVOID_WATER_UNSET, npc.getName()); + } + } + @Command(aliases = { "npc" }, usage = "pathrange [range]", desc = "Sets an NPC's pathfinding range", modifiers = { "pathrange", "pathfindingrange", "prange" }, min = 2, max = 2, permission = "citizens.npc.pathfindingrange") public void pathfindingRange(CommandContext args, CommandSender sender, NPC npc) { @@ -1011,7 +1029,7 @@ public class NPCCommands { if (range > 0 && test.isSpawned() && !Util.locationWithinRange(args.getSenderLocation(), test.getBukkitEntity() - .getLocation(), range)) + .getLocation(), range)) continue; possible.add(test); } diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 0a12ccc1f..5dea42e1a 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -147,6 +147,8 @@ public class Messages { public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit"; public static final String OWNER_SET = "citizens.commands.npc.owner.set"; public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server"; + public static final String PATHFINDING_OPTIONS_AVOID_WATER_SET = "citizens.commands.npc.pathopt.avoid-water-set"; + public static final String PATHFINDING_OPTIONS_AVOID_WATER_UNSET = "citizens.commands.npc.pathopt.avoid-water-unset"; public static final String PATHFINDING_RANGE_SET = "citizens.commands.npc.pathfindingrange.set"; public static final String PLAYER_NOT_FOUND_FOR_SPAWN = "citizens.commands.npc.create.no-player-for-spawn"; public static final String POSE_ADDED = "citizens.commands.npc.pose.added";