diff --git a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java index de9692dd3..ad409bb8d 100644 --- a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java +++ b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java @@ -18,7 +18,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.trait.RotationTrait; -import net.citizensnpcs.trait.RotationTrait.LocalRotationSession; +import net.citizensnpcs.trait.RotationTrait.PacketRotationSession; public class ProtocolLibListener { private final Class flagsClass; @@ -46,7 +46,7 @@ public class ProtocolLibListener { if (trait == null) return; - LocalRotationSession session = trait.getLocalSession(event.getPlayer()); + PacketRotationSession session = trait.getPacketSession(event.getPlayer()); if (session == null || !session.isActive()) return; diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index dd16b492f..8a7539ef4 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -2140,7 +2140,7 @@ public class NPCCommands { yaw = NMS.getHeadYaw(npc.getEntity()); } } - npc.getOrAddTrait(RotationTrait.class).rotateToHave(yaw, pitch); + npc.getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToHave(yaw, pitch); return; } if (yaw != null) { diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index f950e3df3..52cce56cc 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -36,9 +36,11 @@ import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer; import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.DataKey; +import net.citizensnpcs.trait.RotationTrait; +import net.citizensnpcs.trait.RotationTrait.PacketRotationSession; +import net.citizensnpcs.trait.RotationTrait.RotationParams; import net.citizensnpcs.util.ChunkCoord; import net.citizensnpcs.util.NMS; -import net.citizensnpcs.util.Util; public class CitizensNavigator implements Navigator, Runnable { private Location activeTicket; @@ -58,6 +60,7 @@ public class CitizensNavigator implements Navigator, Runnable { private NavigatorParameters localParams = defaultParams; private final NPC npc; private boolean paused; + private PacketRotationSession session; private int stationaryTicks; public CitizensNavigator(NPC npc) { @@ -174,15 +177,11 @@ public class CitizensNavigator implements Navigator, Runnable { localParams.run(); } if (localParams.lookAtFunction() != null) { - Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true, true); - Entity entity = npc.getEntity().getPassenger(); - npcLoc = npc.getEntity().getLocation(); - while (entity != null) { - Location loc = entity.getLocation(STATIONARY_LOCATION); - loc.setYaw(npcLoc.getYaw()); - entity.teleport(loc); - entity = entity.getPassenger(); + if (session == null) { + RotationTrait trait = npc.getOrAddTrait(RotationTrait.class); + session = trait.createPacketSession(new RotationParams().filter((p) -> true).persist(true)); } + session.getSession().rotateToFace(localParams.lookAtFunction().apply(this)); } if (localParams.destinationTeleportMargin() > 0 && npcLoc.distance(targetLoc) <= localParams.destinationTeleportMargin()) { @@ -374,6 +373,10 @@ public class CitizensNavigator implements Navigator, Runnable { private void stopNavigating(CancelReason reason) { if (!isNavigating()) return; + if (session != null) { + session.end(); + session = null; + } Iterator itr = localParams.callbacks().iterator(); List callbacks = new ArrayList(); while (itr.hasNext()) { diff --git a/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java index dbd2a1f42..c83232615 100644 --- a/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java @@ -31,31 +31,32 @@ public class RotationTrait extends Trait { @Persist(reify = true) private final RotationParams globalParameters = new RotationParams(); private final RotationSession globalSession = new RotationSession(globalParameters); - private final List localSessions = Lists.newArrayList(); - private final Map localSessionsByUUID = Maps.newHashMap(); + private final List packetSessions = Lists.newArrayList(); + private final Map packetSessionsByUUID = Maps.newHashMap(); public RotationTrait() { super("rotationtrait"); } - public void clearLocalSessions() { - localSessions.clear(); + public void clearPacketSessions() { + packetSessions.clear(); + packetSessionsByUUID.clear(); } /** * @return The created session */ - public LocalRotationSession createLocalSession(RotationParams params) { + public PacketRotationSession createPacketSession(RotationParams params) { if (params.filter == null && params.uuidFilter == null) throw new IllegalStateException(); RotationSession session = new RotationSession(params); - LocalRotationSession lrs = new LocalRotationSession(session); + PacketRotationSession lrs = new PacketRotationSession(session); if (params.uuidFilter != null) { for (UUID uuid : params.uuidFilter) { - localSessionsByUUID.put(uuid, lrs); + packetSessionsByUUID.put(uuid, lrs); } } else { - localSessions.add(lrs); + packetSessions.add(lrs); } return lrs; } @@ -71,11 +72,11 @@ public class RotationTrait extends Trait { return globalParameters; } - public LocalRotationSession getLocalSession(Player player) { - LocalRotationSession lrs = localSessionsByUUID.get(player.getUniqueId()); + public PacketRotationSession getPacketSession(Player player) { + PacketRotationSession lrs = packetSessionsByUUID.get(player.getUniqueId()); if (lrs != null) return lrs; - for (LocalRotationSession session : localSessions) { + for (PacketRotationSession session : packetSessions) { if (session.accepts(player)) { return session; } @@ -83,6 +84,10 @@ public class RotationTrait extends Trait { return null; } + public RotationSession getPhysicalSession() { + return globalSession; + } + private double getX() { return npc.getStoredLocation().getX(); } @@ -95,44 +100,15 @@ public class RotationTrait extends Trait { return npc.getStoredLocation().getZ(); } - /** - * Rotates to face target entity - * - * @param target - * The target entity to face - */ - public void rotateToFace(Entity target) { - Location loc = target.getLocation(); - loc.setY(loc.getY() + NMS.getHeight(target)); - rotateToFace(loc); - } - - /** - * Rotates to face target location - * - * @param target - * The target location to face - */ - public void rotateToFace(Location target) { - globalSession.setTarget(target); - } - - public void rotateToHave(float yaw, float pitch) { - double pitchCos = Math.cos(Math.toRadians(pitch)); - Vector vector = new Vector(Math.sin(Math.toRadians(yaw)) * -pitchCos, -Math.sin(Math.toRadians(pitch)), - Math.cos(Math.toRadians(yaw)) * pitchCos).normalize(); - rotateToFace(npc.getStoredLocation().clone().add(vector)); - } - @Override public void run() { if (!npc.isSpawned()) return; - Set run = Sets.newHashSet(); - for (Iterator itr = Iterables.concat(localSessions, localSessionsByUUID.values()) + Set run = Sets.newHashSet(); + for (Iterator itr = Iterables.concat(packetSessions, packetSessionsByUUID.values()) .iterator(); itr.hasNext();) { - LocalRotationSession session = itr.next(); + PacketRotationSession session = itr.next(); if (run.contains(session)) continue; run.add(session); @@ -166,12 +142,12 @@ public class RotationTrait extends Trait { } } - public static class LocalRotationSession { + public static class PacketRotationSession { private boolean ended; private final RotationSession session; private RotationTriple triple; - public LocalRotationSession(RotationSession session) { + public PacketRotationSession(RotationSession session) { this.session = session; } @@ -195,6 +171,11 @@ public class RotationTrait extends Trait { return triple.pitch; } + // TODO: inheritance rather than composition? + public RotationSession getSession() { + return session; + } + public boolean isActive() { return !ended && session.isActive(); } @@ -416,6 +397,41 @@ public class RotationTrait extends Trait { return params.persist || t >= 0; } + /** + * Rotates to face target entity + * + * @param target + * The target entity to face + */ + public void rotateToFace(Entity target) { + Location loc = target.getLocation(); + loc.setY(loc.getY() + NMS.getHeight(target)); + rotateToFace(loc); + } + + /** + * Rotates to face target location + * + * @param target + * The target location to face + */ + public void rotateToFace(Location target) { + setTarget(target); + } + + /** + * Rotate to have the given yaw and pitch + * + * @param yaw + * @param pitch + */ + public void rotateToHave(float yaw, float pitch) { + double pitchCos = Math.cos(Math.toRadians(pitch)); + Vector vector = new Vector(Math.sin(Math.toRadians(yaw)) * -pitchCos, -Math.sin(Math.toRadians(pitch)), + Math.cos(Math.toRadians(yaw)) * pitchCos).normalize(); + rotateToFace(npc.getStoredLocation().clone().add(vector)); + } + private void run(RotationTriple rot) { if (!isActive()) return; diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index ea817092c..88759364c 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -786,7 +786,7 @@ public class NMSImpl implements NMSBridge { ((EntityInsentient) handle).aQ += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -810,7 +810,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aQ += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1744,15 +1744,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index be5b01e7d..b7d73e090 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -842,7 +842,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -866,7 +866,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1808,15 +1808,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index 2fde2d38c..17588b0c8 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -849,7 +849,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -874,7 +874,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1818,15 +1818,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index 7060f3cff..17c68313e 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -885,7 +885,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aS += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -909,7 +909,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aS += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1935,15 +1935,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index 807448277..b9ed7998f 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -950,7 +950,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aM += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -974,7 +974,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aM += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -2073,15 +2073,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 347ea7336..7daf7dad5 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -962,7 +962,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -986,7 +986,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -2128,15 +2128,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index b7888600b..a9d54448d 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -986,7 +986,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aC += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1010,7 +1010,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aC += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -2100,15 +2100,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index cbf22c40c..90a191b86 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -991,7 +991,7 @@ public class NMSImpl implements NMSBridge { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1015,7 +1015,7 @@ public class NMSImpl implements NMSBridge { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -2094,15 +2094,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index 2687386ba..d0b4508b2 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -997,7 +997,7 @@ public class NMSImpl implements NMSBridge { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1022,7 +1022,7 @@ public class NMSImpl implements NMSBridge { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -2101,15 +2101,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java index a58ff77bf..c0fb4e01a 100644 --- a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java +++ b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java @@ -603,6 +603,7 @@ public class NMSImpl implements NMSBridge { try { return (GameProfile) SKULL_PROFILE_FIELD.get(meta); } catch (Exception e) { + e.printStackTrace(); return null; } } @@ -1018,7 +1019,7 @@ public class NMSImpl implements NMSBridge { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1043,7 +1044,7 @@ public class NMSImpl implements NMSBridge { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -2135,15 +2136,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } } diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index f6ff6173f..1de4c3710 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -63,6 +63,7 @@ import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse; import com.mojang.util.UUIDTypeAdapter; import net.citizensnpcs.Settings.Setting; +import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.event.CancelReason; import net.citizensnpcs.api.command.CommandManager; @@ -732,7 +733,7 @@ public class NMSImpl implements NMSBridge { ((EntityInsentient) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -755,7 +756,7 @@ public class NMSImpl implements NMSBridge { ((EntityLiving) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).getPhysicalSession().rotateToFace(to); } } @@ -1623,15 +1624,15 @@ public class NMSImpl implements NMSBridge { public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { radius *= radius; final org.bukkit.World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) { + if (world != player.getWorld() || (from != null && !player.canSee(from))) { continue; } - if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + if (location.distanceSquared(player.getLocation(PACKET_CACHE_LOCATION)) > radius) { continue; } for (Packet packet : packets) { - NMSImpl.sendPacket(ply, packet); + NMSImpl.sendPacket(player, packet); } } }