mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-03 05:51:42 +01:00
Fixed human npcs not updating properly, exclude some types from waypoints
This commit is contained in:
parent
f610651dbc
commit
c7eb4eb1b0
@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -106,8 +108,12 @@ public class CommandManager {
|
|||||||
&& !player.hasPermission("citizens.admin"))
|
&& !player.hasPermission("citizens.admin"))
|
||||||
throw new RequirementMissingException("You must be the owner of this NPC to execute that command.");
|
throw new RequirementMissingException("You must be the owner of this NPC to execute that command.");
|
||||||
|
|
||||||
Set<EntityType> types = Sets.newHashSet(cmdRequirements.types());
|
if (npc != null) {
|
||||||
if (!types.contains(EntityType.UNKNOWN)) {
|
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());
|
EntityType type = EntityType.valueOf(npc.getTrait(MobType.class).getType());
|
||||||
if (!types.contains(type)) {
|
if (!types.contains(type)) {
|
||||||
throw new RequirementMissingException("The NPC cannot be the mob type '"
|
throw new RequirementMissingException("The NPC cannot be the mob type '"
|
||||||
|
@ -13,4 +13,6 @@ public @interface Requirements {
|
|||||||
boolean selected() default false;
|
boolean selected() default false;
|
||||||
|
|
||||||
EntityType[] types() default { EntityType.UNKNOWN };
|
EntityType[] types() default { EntityType.UNKNOWN };
|
||||||
|
|
||||||
|
EntityType[] excludedTypes() default { EntityType.UNKNOWN };
|
||||||
}
|
}
|
@ -37,7 +37,8 @@ public class EditorCommands {
|
|||||||
min = 1,
|
min = 1,
|
||||||
max = 1,
|
max = 1,
|
||||||
permission = "npc.edit.path")
|
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) {
|
public void path(CommandContext args, Player player, NPC npc) {
|
||||||
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
|
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,9 @@ public class CitizensAI implements AI {
|
|||||||
public void setDestination(Location destination) {
|
public void setDestination(Location destination) {
|
||||||
if (destination == null)
|
if (destination == null)
|
||||||
throw new IllegalArgumentException("destination cannot be null");
|
throw new IllegalArgumentException("destination cannot be null");
|
||||||
|
if (!npc.isSpawned())
|
||||||
|
throw new IllegalStateException("npc is not spawned");
|
||||||
|
|
||||||
boolean replaced = executing != null;
|
boolean replaced = executing != null;
|
||||||
executing = new MCNavigationStrategy(npc, destination);
|
executing = new MCNavigationStrategy(npc, destination);
|
||||||
|
|
||||||
|
@ -62,9 +62,6 @@ public class MCNavigationStrategy implements PathStrategy {
|
|||||||
public boolean update() {
|
public boolean update() {
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
navigation.d();
|
navigation.d();
|
||||||
entity.getControllerMove().c();
|
|
||||||
entity.getControllerLook().a();
|
|
||||||
entity.getControllerJump().b();
|
|
||||||
entity.moveOnCurrentHeading();
|
entity.moveOnCurrentHeading();
|
||||||
}
|
}
|
||||||
return navigation.e();
|
return navigation.e();
|
||||||
|
@ -42,12 +42,15 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void d_() {
|
public void F_() {
|
||||||
super.d_();
|
super.F_();
|
||||||
npc.update();
|
npc.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveOnCurrentHeading() {
|
public void moveOnCurrentHeading() {
|
||||||
|
getControllerMove().c();
|
||||||
|
getControllerLook().a();
|
||||||
|
getControllerJump().b();
|
||||||
if (this.aZ) {
|
if (this.aZ) {
|
||||||
if (aT()) {
|
if (aT()) {
|
||||||
this.motY += 0.03999999910593033D;
|
this.motY += 0.03999999910593033D;
|
||||||
|
@ -60,7 +60,8 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
|||||||
return;
|
return;
|
||||||
if (hasInvalidTarget()) {
|
if (hasInvalidTarget()) {
|
||||||
findNewTarget();
|
findNewTarget();
|
||||||
} else {
|
}
|
||||||
|
if (lookingAt != null) {
|
||||||
faceEntity(npc.getBukkitEntity(), lookingAt);
|
faceEntity(npc.getBukkitEntity(), lookingAt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,13 +86,18 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasInvalidTarget() {
|
private boolean hasInvalidTarget() {
|
||||||
return lookingAt == null || !lookingAt.isOnline()
|
if (lookingAt == null)
|
||||||
|| lookingAt.getLocation().distanceSquared(npc.getBukkitEntity().getLocation()) > 5;
|
return true;
|
||||||
|
if (!lookingAt.isOnline() || lookingAt.getLocation().distanceSquared(npc.getBukkitEntity().getLocation()) > 5) {
|
||||||
|
lookingAt = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(DataKey key) {
|
public void save(DataKey key) {
|
||||||
key.setBoolean("enabled", enabled);
|
key.setBoolean("", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user