mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 11:38:26 +01:00
Fixed human npcs not updating properly, exclude some types from waypoints
This commit is contained in:
parent
d17e49ee74
commit
56ea9bbddb
@ -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 '"
|
||||
|
@ -13,4 +13,6 @@ public @interface Requirements {
|
||||
boolean selected() default false;
|
||||
|
||||
EntityType[] types() default { EntityType.UNKNOWN };
|
||||
|
||||
EntityType[] excludedTypes() default { EntityType.UNKNOWN };
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user