Trim arguments, waypoint command

This commit is contained in:
fullwall 2012-10-23 15:14:54 +08:00
parent 3c9379d455
commit 66c2773616
5 changed files with 26 additions and 4 deletions

View File

@ -89,9 +89,10 @@ public class CommandContext {
}
List<String> 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()]);
}

View File

@ -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)",

View File

@ -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

View File

@ -31,7 +31,6 @@ public class CurrentLocation extends Trait {
public void run() {
if (!npc.isSpawned())
return;
loc = npc.getBukkitEntity().getLocation();
}

View File

@ -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";
}