From 56ea9bbddb859336fd1b2b4463b38786d2409438 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 30 Apr 2012 22:56:27 +0800 Subject: [PATCH] Fixed human npcs not updating properly, exclude some types from waypoints --- .../net/citizensnpcs/command/CommandManager.java | 10 ++++++++-- .../net/citizensnpcs/command/Requirements.java | 2 ++ .../command/command/EditorCommands.java | 3 ++- .../java/net/citizensnpcs/npc/ai/CitizensAI.java | 3 +++ .../citizensnpcs/npc/ai/MCNavigationStrategy.java | 3 --- .../citizensnpcs/npc/entity/EntityHumanNPC.java | 7 +++++-- .../java/net/citizensnpcs/trait/LookClose.java | 14 ++++++++++---- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/citizensnpcs/command/CommandManager.java b/src/main/java/net/citizensnpcs/command/CommandManager.java index c6fa51059..5124af057 100644 --- a/src/main/java/net/citizensnpcs/command/CommandManager.java +++ b/src/main/java/net/citizensnpcs/command/CommandManager.java @@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -106,8 +108,12 @@ public class CommandManager { && !player.hasPermission("citizens.admin")) throw new RequirementMissingException("You must be the owner of this NPC to execute that command."); - Set types = Sets.newHashSet(cmdRequirements.types()); - if (!types.contains(EntityType.UNKNOWN)) { + if (npc != null) { + Set types = Sets.newEnumSet(Arrays.asList(cmdRequirements.types()), EntityType.class); + if (types.contains(EntityType.UNKNOWN)) + types = EnumSet.allOf(EntityType.class); + types.removeAll(Sets.newHashSet(cmdRequirements.excludedTypes())); + EntityType type = EntityType.valueOf(npc.getTrait(MobType.class).getType()); if (!types.contains(type)) { throw new RequirementMissingException("The NPC cannot be the mob type '" diff --git a/src/main/java/net/citizensnpcs/command/Requirements.java b/src/main/java/net/citizensnpcs/command/Requirements.java index d73c3b425..b2afbfd9f 100644 --- a/src/main/java/net/citizensnpcs/command/Requirements.java +++ b/src/main/java/net/citizensnpcs/command/Requirements.java @@ -13,4 +13,6 @@ public @interface Requirements { boolean selected() default false; EntityType[] types() default { EntityType.UNKNOWN }; + + EntityType[] excludedTypes() default { EntityType.UNKNOWN }; } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/command/command/EditorCommands.java b/src/main/java/net/citizensnpcs/command/command/EditorCommands.java index 46a78206b..d7501eadd 100644 --- a/src/main/java/net/citizensnpcs/command/command/EditorCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/EditorCommands.java @@ -37,7 +37,8 @@ public class EditorCommands { min = 1, max = 1, permission = "npc.edit.path") - @Requirements(selected = true, ownership = true) + @Requirements(selected = true, ownership = true, excludedTypes = { EntityType.ENDER_DRAGON, EntityType.SQUID, + EntityType.GHAST, EntityType.BLAZE }) public void path(CommandContext args, Player player, NPC npc) { Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player)); } diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensAI.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensAI.java index a32c9ecc2..072289e6b 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensAI.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensAI.java @@ -98,6 +98,9 @@ public class CitizensAI implements AI { public void setDestination(Location destination) { if (destination == null) throw new IllegalArgumentException("destination cannot be null"); + if (!npc.isSpawned()) + throw new IllegalStateException("npc is not spawned"); + boolean replaced = executing != null; executing = new MCNavigationStrategy(npc, destination); diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java index 24e2a447f..2ef9bbef3 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java @@ -62,9 +62,6 @@ public class MCNavigationStrategy implements PathStrategy { public boolean update() { if (entity != null) { navigation.d(); - entity.getControllerMove().c(); - entity.getControllerLook().a(); - entity.getControllerJump().b(); entity.moveOnCurrentHeading(); } return navigation.e(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index c46268299..50dad6e1d 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -42,12 +42,15 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle { } @Override - public void d_() { - super.d_(); + public void F_() { + super.F_(); npc.update(); } public void moveOnCurrentHeading() { + getControllerMove().c(); + getControllerLook().a(); + getControllerJump().b(); if (this.aZ) { if (aT()) { this.motY += 0.03999999910593033D; diff --git a/src/main/java/net/citizensnpcs/trait/LookClose.java b/src/main/java/net/citizensnpcs/trait/LookClose.java index e6edddfe1..78a9eb1fd 100644 --- a/src/main/java/net/citizensnpcs/trait/LookClose.java +++ b/src/main/java/net/citizensnpcs/trait/LookClose.java @@ -60,7 +60,8 @@ public class LookClose extends Trait implements Runnable, Toggleable { return; if (hasInvalidTarget()) { findNewTarget(); - } else { + } + if (lookingAt != null) { faceEntity(npc.getBukkitEntity(), lookingAt); } } @@ -85,13 +86,18 @@ public class LookClose extends Trait implements Runnable, Toggleable { } private boolean hasInvalidTarget() { - return lookingAt == null || !lookingAt.isOnline() - || lookingAt.getLocation().distanceSquared(npc.getBukkitEntity().getLocation()) > 5; + if (lookingAt == null) + return true; + if (!lookingAt.isOnline() || lookingAt.getLocation().distanceSquared(npc.getBukkitEntity().getLocation()) > 5) { + lookingAt = null; + return true; + } + return false; } @Override public void save(DataKey key) { - key.setBoolean("enabled", enabled); + key.setBoolean("", enabled); } @Override