From eb9764aeb07d8b53eb7273e7898504315361cd47 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 20 Jan 2021 20:27:46 +0800 Subject: [PATCH] Further refactor lookclose --- .../main/java/net/citizensnpcs/trait/LookClose.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/LookClose.java b/main/src/main/java/net/citizensnpcs/trait/LookClose.java index 15910784f..36becdbad 100644 --- a/main/src/main/java/net/citizensnpcs/trait/LookClose.java +++ b/main/src/main/java/net/citizensnpcs/trait/LookClose.java @@ -67,22 +67,19 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable * Finds a new look-close target */ public void findNewTarget() { - double min = Integer.MAX_VALUE; + double min = range * range; for (Entity entity : npc.getEntity().getNearbyEntities(range, range, range)) { if (!(entity instanceof Player)) continue; - Player player = (Player) entity; Location location = player.getLocation(CACHE_LOCATION); if (location.getWorld() != NPC_LOCATION.getWorld()) continue; double dist = location.distanceSquared(NPC_LOCATION); - if (dist > range * range || CitizensAPI.getNPCRegistry().getNPC(entity) != null || isInvisible(player)) + if (dist > min || CitizensAPI.getNPCRegistry().getNPC(entity) != null || isInvisible(player)) continue; - if (dist < min) { - min = dist; - lookingAt = player; - } + min = dist; + lookingAt = player; } }