Skip to content

Commit

Permalink
Respect canSee when sending packets
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 17, 2014
1 parent 9875cc8 commit cc4c818
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;

Expand Down Expand Up @@ -217,7 +218,8 @@ public void update() {
navigator.run();

if (!getNavigator().isNavigating() && getEntity().getWorld().getTime() % 30 == 0) {
NMS.sendPacketNearby(getStoredLocation(),
Player player = getEntity() instanceof Player ? (Player) getEntity() : null;
NMS.sendPacketNearby(player, getStoredLocation(),
new PacketPlayOutEntityTeleport(NMS.getHandle(getEntity())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private void updatePackets(boolean navigating) {
packets[5] = new PacketPlayOutPlayerInfo(getBukkitEntity().getPlayerListName(), !removeFromPlayerList,
removeFromPlayerList ? 9999 : ping);
}
NMS.sendPacketsNearby(current, packets);
NMS.sendPacketsNearby(getBukkitEntity(), current, packets);
packetUpdateCount = 0;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/citizensnpcs/util/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,19 @@ public static void sendPacket(Player player, Packet packet) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}

public static void sendPacketNearby(Location location, Packet packet) {
NMS.sendPacketsNearby(location, Arrays.asList(packet), 64);
public static void sendPacketNearby(Player from, Location location, Packet packet) {
NMS.sendPacketsNearby(from, location, Arrays.asList(packet), 64);
}

public static void sendPacketsNearby(Location location, Collection<Packet> packets) {
NMS.sendPacketsNearby(location, packets, 64);
public static void sendPacketsNearby(Player from, Location location, Collection<Packet> packets) {
NMS.sendPacketsNearby(from, location, packets, 64);
}

public static void sendPacketsNearby(Location location, Collection<Packet> packets, double radius) {
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()) {
if (ply == null || world != ply.getWorld() || (from != null && ply.canSee(from))) {
continue;
}
if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) {
Expand All @@ -366,8 +366,8 @@ public static void sendPacketsNearby(Location location, Collection<Packet> packe
}
}

public static void sendPacketsNearby(Location location, Packet... packets) {
NMS.sendPacketsNearby(location, Arrays.asList(packets), 64);
public static void sendPacketsNearby(Player from, Location location, Packet... packets) {
NMS.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
}

public static void sendToOnline(Packet... packets) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/citizensnpcs/util/PlayerAnimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ protected void playDefaultAnimation(EntityPlayer player, int radius, int code) {
}

protected void sendPacketNearby(Packet packet, EntityPlayer player, int radius) {
NMS.sendPacketsNearby(player.getBukkitEntity().getLocation(), Arrays.asList(packet), radius);
NMS.sendPacketsNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), Arrays.asList(packet),
radius);
}
}

0 comments on commit cc4c818

Please sign in to comment.