mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-25 13:53:02 +02:00
Make lookclose more consistent at looking at players
This commit is contained in:
parent
3f4a4af581
commit
58443ee726
@ -75,9 +75,11 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
continue;
|
||||
|
||||
Player player = (Player) entity;
|
||||
if (CitizensAPI.getNPCRegistry().getNPC(entity) != null || player.getGameMode() == GameMode.SPECTATOR
|
||||
|| entity.getLocation(CACHE_LOCATION).getWorld() != NPC_LOCATION.getWorld()
|
||||
|| player.hasPotionEffect(PotionEffectType.INVISIBILITY) || isPluginVanished((Player) entity))
|
||||
Location location = player.getLocation(CACHE_LOCATION);
|
||||
if (location.getWorld() != NPC_LOCATION.getWorld())
|
||||
continue;
|
||||
double dist = location.distanceSquared(NPC_LOCATION);
|
||||
if (dist > range || CitizensAPI.getNPCRegistry().getNPC(entity) != null || isInvisible(player))
|
||||
continue;
|
||||
nearby.add(player);
|
||||
}
|
||||
@ -91,7 +93,6 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
}
|
||||
return Double.compare(l1.distanceSquared(NPC_LOCATION), l2.distanceSquared(NPC_LOCATION));
|
||||
});
|
||||
|
||||
lookingAt = nearby.get(0);
|
||||
}
|
||||
}
|
||||
@ -119,7 +120,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
private boolean hasInvalidTarget() {
|
||||
if (lookingAt == null)
|
||||
return true;
|
||||
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getEntity().getWorld()
|
||||
if (!lookingAt.isOnline() || !lookingAt.isValid() || lookingAt.getWorld() != npc.getEntity().getWorld()
|
||||
|| isInvisible(lookingAt)
|
||||
|| lookingAt.getLocation(PLAYER_LOCATION).distanceSquared(NPC_LOCATION) > range * range) {
|
||||
lookingAt = null;
|
||||
}
|
||||
@ -130,6 +132,11 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
return Math.abs(array[0] - array[1]) < 0.001;
|
||||
}
|
||||
|
||||
private boolean isInvisible(Player player) {
|
||||
return player.getGameMode() == GameMode.SPECTATOR || player.hasPotionEffect(PotionEffectType.INVISIBILITY)
|
||||
|| isPluginVanished(player);
|
||||
}
|
||||
|
||||
private boolean isPluginVanished(Player player) {
|
||||
for (MetadataValue meta : player.getMetadata("vanished")) {
|
||||
if (meta.asBoolean()) {
|
||||
|
Loading…
Reference in New Issue
Block a user