From 66c2773616c525b1476bb01f4e13751f28fd5223 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 23 Oct 2012 15:14:54 +0800 Subject: [PATCH] Trim arguments, waypoint command --- .../net/citizensnpcs/command/CommandContext.java | 5 +++-- .../command/command/WaypointCommands.java | 15 +++++++++++++++ .../citizensnpcs/npc/ai/CitizensNavigator.java | 8 +++++++- .../net/citizensnpcs/trait/CurrentLocation.java | 1 - src/main/java/net/citizensnpcs/util/Messages.java | 1 + 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/citizensnpcs/command/CommandContext.java b/src/main/java/net/citizensnpcs/command/CommandContext.java index b1bb13688..92c6e93e4 100644 --- a/src/main/java/net/citizensnpcs/command/CommandContext.java +++ b/src/main/java/net/citizensnpcs/command/CommandContext.java @@ -89,9 +89,10 @@ public class CommandContext { } List copied = Lists.newArrayList(); for (String arg : args) { - if (arg == null || arg.trim().isEmpty()) + arg = arg.trim(); + if (arg == null || arg.isEmpty()) continue; - copied.add(arg); + copied.add(arg.trim()); } this.args = copied.toArray(new String[copied.size()]); } diff --git a/src/main/java/net/citizensnpcs/command/command/WaypointCommands.java b/src/main/java/net/citizensnpcs/command/command/WaypointCommands.java index 6f3b41f6b..08382662d 100644 --- a/src/main/java/net/citizensnpcs/command/command/WaypointCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/WaypointCommands.java @@ -17,6 +17,21 @@ public class WaypointCommands { public WaypointCommands(Citizens plugin) { } + // TODO: refactor into a policy style system + @Command( + aliases = { "waypoints", "waypoint", "wp" }, + usage = "disableteleporting", + desc = "Disables teleportation when stuck (temporary command)", + modifiers = { "disableteleport" }, + min = 1, + max = 1, + permission = "waypoints.disableteleport") + public void disableTeleporting(CommandContext args, CommandSender sender, NPC npc) + throws CommandException { + npc.getNavigator().getDefaultParameters().stuckAction(null); + Messaging.sendTr(sender, Messages.WAYPOINT_TELEPORTING_DISABLED); + } + @Command( aliases = { "waypoints", "waypoint", "wp" }, usage = "provider (provider name) (-a)", diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index a52cfcf8b..30c791b4f 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -6,6 +6,7 @@ import net.citizensnpcs.api.ai.Navigator; import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.StuckAction; import net.citizensnpcs.api.ai.TargetType; +import net.citizensnpcs.api.ai.TeleportStuckAction; import net.citizensnpcs.api.ai.event.CancelReason; import net.citizensnpcs.api.ai.event.NavigationBeginEvent; import net.citizensnpcs.api.ai.event.NavigationCancelEvent; @@ -24,7 +25,8 @@ import org.bukkit.entity.LivingEntity; public class CitizensNavigator implements Navigator { private final NavigatorParameters defaultParams = new NavigatorParameters() .baseSpeed(UNINITIALISED_SPEED).range(Setting.DEFAULT_PATHFINDING_RANGE.asFloat()) - .stationaryTicks(Setting.DEFAULT_STATIONARY_TICKS.asInt()); + .stationaryTicks(Setting.DEFAULT_STATIONARY_TICKS.asInt()) + .stuckAction(TeleportStuckAction.INSTANCE); private PathStrategy executing; private int lastX, lastY, lastZ; private NavigatorParameters localParams = defaultParams; @@ -87,6 +89,9 @@ public class CitizensNavigator implements Navigator { defaultParams.speedModifier((float) root.getDouble("speedmodifier", 1F)); if (root.keyExists("avoidwater")) defaultParams.avoidWater(root.getBoolean("avoidwater")); + if (!root.getBoolean("usedefaultstuckaction") + && defaultParams.stuckAction() == TeleportStuckAction.INSTANCE) + defaultParams.stuckAction(null); } public void onSpawn() { @@ -106,6 +111,7 @@ public class CitizensNavigator implements Navigator { root.setInt("stationaryticks", defaultParams.stationaryTicks()); root.setDouble("speedmodifier", defaultParams.speedModifier()); root.setBoolean("avoidwater", defaultParams.avoidWater()); + root.setBoolean("usedefaultstuckaction", defaultParams.stuckAction() == TeleportStuckAction.INSTANCE); } @Override diff --git a/src/main/java/net/citizensnpcs/trait/CurrentLocation.java b/src/main/java/net/citizensnpcs/trait/CurrentLocation.java index 0cb55c0cd..ca30dd820 100644 --- a/src/main/java/net/citizensnpcs/trait/CurrentLocation.java +++ b/src/main/java/net/citizensnpcs/trait/CurrentLocation.java @@ -31,7 +31,6 @@ public class CurrentLocation extends Trait { public void run() { if (!npc.isSpawned()) return; - loc = npc.getBukkitEntity().getLocation(); } diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 822de6586..405a836ee 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -178,5 +178,6 @@ public class Messages { public static final String VULNERABLE_SET = "citizens.commands.npc.vulnerable.set"; public static final String VULNERABLE_STOPPED = "citizens.commands.npc.vulnerable.stopped"; public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider"; + public static final String WAYPOINT_TELEPORTING_DISABLED = "citizens.commands.waypoints.disableteleporting.disabled"; public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default"; }