Fix /npc follow <NPC ID>

This commit is contained in:
fullwall 2023-03-31 00:11:29 +08:00
parent e3e2d16eb2
commit e0a66ff67b
3 changed files with 25 additions and 38 deletions

View File

@ -960,8 +960,7 @@ public class NPCCommands {
if (!(sender instanceof ConsoleCommandSender)
&& !followingNPC.getOrAddTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(CommandMessages.MUST_BE_OWNER);
boolean following = followingNPC.getOrAddTrait(FollowTrait.class).toggle(followingNPC.getEntity(),
protect);
boolean following = npc.getOrAddTrait(FollowTrait.class).toggle(followingNPC.getEntity(), protect);
Messaging.sendTr(sender, following ? Messages.FOLLOW_SET : Messages.FOLLOW_UNSET, npc.getName(),
followingNPC.getName());
};

View File

@ -283,7 +283,7 @@ public class CitizensNavigator implements Navigator, Runnable {
cancelNavigation();
return;
}
setTarget((params) -> {
setTarget(params -> {
params.straightLineTargetingDistance(100000);
return new MCTargetStrategy(npc, target, aggressive, params);
});
@ -297,7 +297,7 @@ public class CitizensNavigator implements Navigator, Runnable {
cancelNavigation();
return;
}
setTarget((params) -> new StraightLineNavigationStrategy(npc, target.clone(), params));
setTarget(params -> new StraightLineNavigationStrategy(npc, target.clone(), params));
}
@Override
@ -308,12 +308,7 @@ public class CitizensNavigator implements Navigator, Runnable {
cancelNavigation();
return;
}
setTarget(new Function<NavigatorParameters, PathStrategy>() {
@Override
public PathStrategy apply(NavigatorParameters params) {
return new MCTargetStrategy(npc, target, aggressive, params);
}
});
setTarget(params -> new MCTargetStrategy(npc, target, aggressive, params));
}
@Override
@ -332,17 +327,14 @@ public class CitizensNavigator implements Navigator, Runnable {
cancelNavigation();
return;
}
setTarget(new Function<NavigatorParameters, PathStrategy>() {
@Override
public PathStrategy apply(NavigatorParameters params) {
if (npc.isFlyable()) {
return new FlyingAStarNavigationStrategy(npc, path, params);
} else if (params.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)
|| npc.getEntity() instanceof ArmorStand) {
return new AStarNavigationStrategy(npc, path, params);
} else {
return new MCNavigationStrategy(npc, path, params);
}
setTarget(params -> {
if (npc.isFlyable()) {
return new FlyingAStarNavigationStrategy(npc, path, params);
} else if (params.useNewPathfinder()
|| (!(npc.getEntity() instanceof LivingEntity) && !(npc.getEntity() instanceof ArmorStand))) {
return new AStarNavigationStrategy(npc, path, params);
} else {
return new MCNavigationStrategy(npc, path, params);
}
});
}
@ -356,17 +348,14 @@ public class CitizensNavigator implements Navigator, Runnable {
return;
}
final Location target = targetIn.clone();
setTarget(new Function<NavigatorParameters, PathStrategy>() {
@Override
public PathStrategy apply(NavigatorParameters params) {
if (npc.isFlyable()) {
return new FlyingAStarNavigationStrategy(npc, target, params);
} else if (params.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)
|| npc.getEntity() instanceof ArmorStand) {
return new AStarNavigationStrategy(npc, target, params);
} else {
return new MCNavigationStrategy(npc, target, params);
}
setTarget(params -> {
if (npc.isFlyable()) {
return new FlyingAStarNavigationStrategy(npc, target, params);
} else if (params.useNewPathfinder()
|| (!(npc.getEntity() instanceof LivingEntity) && !(npc.getEntity() instanceof ArmorStand))) {
return new AStarNavigationStrategy(npc, target, params);
} else {
return new MCNavigationStrategy(npc, target, params);
}
});
}

View File

@ -80,16 +80,15 @@ public class FollowTrait extends Trait {
return;
entity = Bukkit.getPlayer(followingUUID);
if (entity == null) {
return;
entity = Bukkit.getEntity(followingUUID);
}
entity = Bukkit.getEntity(followingUUID);
if (entity == null) {
if (entity == null)
return;
}
}
if (!isActive()) {
if (!isActive())
return;
}
if (!npc.getEntity().getWorld().equals(entity.getWorld())) {
if (Setting.FOLLOW_ACROSS_WORLDS.asBoolean()) {
npc.teleport(entity.getLocation(), TeleportCause.PLUGIN);