From 482eb05766030e0ba6714bfb9f846143c38baec7 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 16 Mar 2013 13:28:26 +0800 Subject: [PATCH] Misc. fixes --- src/main/java/net/citizensnpcs/EventListen.java | 3 ++- .../java/net/citizensnpcs/commands/NPCCommands.java | 11 ++++++++--- .../net/citizensnpcs/commands/WaypointCommands.java | 6 +++--- src/main/java/net/citizensnpcs/npc/CitizensNPC.java | 2 +- .../net/citizensnpcs/npc/ai/CitizensNavigator.java | 10 +++++----- .../trait/waypoint/WanderWaypointProvider.java | 2 +- src/main/java/net/citizensnpcs/util/NMS.java | 4 +++- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 37eae2f3f..504f9a2d9 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -182,8 +182,9 @@ public class EventListen implements Listener { @EventHandler public void onNPCDespawn(NPCDespawnEvent event) { - if (event.getReason() == DespawnReason.PLUGIN || event.getReason() == DespawnReason.REMOVAL) + if (event.getReason() == DespawnReason.PLUGIN || event.getReason() == DespawnReason.REMOVAL) { toRespawn.remove(toCoord(event.getNPC().getBukkitEntity().getLocation()), event.getNPC()); + } } @EventHandler(ignoreCancelled = true) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index aecfbeac9..f3043d405 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -1170,9 +1170,14 @@ public class NPCCommands { wolf.setSitting(args.hasFlag('s')); wolf.setTamed(args.hasFlag('t')); if (args.hasValueFlag("collar")) { - String unparsed = args.getFlag("colour"); - int rgb = Integer.parseInt(unparsed.replace("#", "")); - DyeColor color = DyeColor.getByColor(org.bukkit.Color.fromRGB(rgb)); + String unparsed = args.getFlag("collar"); + DyeColor color = null; + try { + DyeColor.valueOf(unparsed.toUpperCase().replace(' ', '_')); + } catch (IllegalArgumentException e) { + int rgb = Integer.parseInt(unparsed.replace("#", "")); + color = DyeColor.getByColor(org.bukkit.Color.fromRGB(rgb)); + } if (color == null) throw new CommandException(Messages.COLLAR_COLOUR_NOT_RECOGNISED); wolf.setCollarColor(color); diff --git a/src/main/java/net/citizensnpcs/commands/WaypointCommands.java b/src/main/java/net/citizensnpcs/commands/WaypointCommands.java index 0148ad98e..0bdedc507 100644 --- a/src/main/java/net/citizensnpcs/commands/WaypointCommands.java +++ b/src/main/java/net/citizensnpcs/commands/WaypointCommands.java @@ -33,17 +33,17 @@ public class WaypointCommands { @Command( aliases = { "waypoints", "waypoint", "wp" }, - usage = "provider [provider name] (-a)", + usage = "provider [provider name] (-d)", desc = "Sets the current waypoint provider", modifiers = { "provider" }, min = 1, max = 2, - flags = "a", + flags = "d", permission = "citizens.waypoints.provider") public void provider(CommandContext args, CommandSender sender, NPC npc) throws CommandException { Waypoints waypoints = npc.getTrait(Waypoints.class); if (args.argsLength() == 1) { - if (args.hasFlag('a')) { + if (args.hasFlag('d')) { waypoints.describeProviders(sender); } else Messaging.sendTr(sender, Messages.CURRENT_WAYPOINT_PROVIDER, waypoints.getCurrentProviderName()); diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 296232ade..0e0ad8152 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -69,7 +69,7 @@ public class CitizensNPC extends AbstractNPC { for (Trait trait : traits.values()) trait.onDespawn(); entityController.remove(); - + navigator.onDespawn(); return true; } diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 3a3f88605..ba80de801 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -93,6 +93,10 @@ public class CitizensNavigator implements Navigator, Runnable { defaultParams.stuckAction(null); } + public void onDespawn() { + stopNavigating(CancelReason.NPC_DESPAWNED); + } + public void onSpawn() { if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) defaultParams.baseSpeed(NMS.getSpeedFor(npc)); @@ -103,11 +107,6 @@ public class CitizensNavigator implements Navigator, Runnable { public void run() { if (!isNavigating()) return; - if (!npc.isSpawned()) { - if (isNavigating()) - stopNavigating(CancelReason.NPC_DESPAWNED); - return; - } if (updateStationaryStatus()) return; updatePathfindingRange(); @@ -235,5 +234,6 @@ public class CitizensNavigator implements Navigator, Runnable { } private static final Location STATIONARY_LOCATION = new Location(null, 0, 0, 0); + private static int UNINITIALISED_SPEED = Integer.MIN_VALUE; } diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java index b5de035c8..03f9848cb 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -11,7 +11,7 @@ import org.bukkit.entity.Player; public class WanderWaypointProvider implements WaypointProvider { private Goal currentGoal; private volatile boolean paused; - private int xrange, yrange; + private int xrange = DEFAULT_XRANGE, yrange = DEFAULT_YRANGE; @Override public WaypointEditor createEditor(Player player) { diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index 1843107fd..123629c08 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -275,8 +275,10 @@ public class NMS { yaw -= 360.0F; } handle.aA = yaw; - if (!(handle instanceof EntityHuman)) + if (!(handle instanceof EntityHuman)) { handle.ay = yaw; + handle.az = yaw; + } } public static void setLandSpeedModifier(EntityLiving handle, float speed) {