Make lookAtFunction use packets for yaw, tweak API further

This commit is contained in:
fullwall 2022-12-06 23:50:11 +08:00
parent 6533cdccf8
commit d34fd48533
15 changed files with 144 additions and 123 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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<NavigatorCallback> itr = localParams.callbacks().iterator();
List<NavigatorCallback> callbacks = new ArrayList<NavigatorCallback>();
while (itr.hasNext()) {

View File

@ -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<LocalRotationSession> localSessions = Lists.newArrayList();
private final Map<UUID, LocalRotationSession> localSessionsByUUID = Maps.newHashMap();
private final List<PacketRotationSession> packetSessions = Lists.newArrayList();
private final Map<UUID, PacketRotationSession> 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<LocalRotationSession> run = Sets.newHashSet();
for (Iterator<LocalRotationSession> itr = Iterables.concat(localSessions, localSessionsByUUID.values())
Set<PacketRotationSession> run = Sets.newHashSet();
for (Iterator<PacketRotationSession> 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;

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}

View File

@ -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<Packet<?>> 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);
}
}
}