Fixed human npcs not updating properly, exclude some types from waypoints

This commit is contained in:
fullwall 2012-04-30 22:56:27 +08:00
parent d17e49ee74
commit 56ea9bbddb
7 changed files with 30 additions and 12 deletions

View File

@ -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<EntityType> types = Sets.newHashSet(cmdRequirements.types());
if (!types.contains(EntityType.UNKNOWN)) {
if (npc != null) {
Set<EntityType> 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 '"

View File

@ -13,4 +13,6 @@ public @interface Requirements {
boolean selected() default false;
EntityType[] types() default { EntityType.UNKNOWN };
EntityType[] excludedTypes() default { EntityType.UNKNOWN };
}

View File

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

View File

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

View File

@ -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();

View File

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

View File

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