From 5b545d96e9c5475b9ea5aa894c13ecfea3e01398 Mon Sep 17 00:00:00 2001 From: Morphan1 Date: Tue, 10 Mar 2015 03:14:43 -0400 Subject: [PATCH 1/4] Improve tablist removal and skin updating --- .../java/net/citizensnpcs/EventListen.java | 34 +++++++++++++++++++ .../util/nms/PlayerlistTrackerEntry.java | 11 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 00b1434a3..dd99daa25 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -30,9 +30,13 @@ import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.NMS; +import net.minecraft.server.v1_8_R2.EntityPlayer; +import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -49,6 +53,7 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.world.ChunkLoadEvent; @@ -60,6 +65,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; +import org.bukkit.scheduler.BukkitRunnable; public class EventListen implements Listener { private final NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry(); @@ -272,6 +278,34 @@ public class EventListen implements Listener { Bukkit.getPluginManager().callEvent(rightClickEvent); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerJoin(final PlayerJoinEvent event) { + new BukkitRunnable() { + @Override + public void run() { + Messaging.send(Bukkit.getConsoleSender(), "TEST ENTITIES"); + Player player = event.getPlayer(); + for (Entity entity : player.getNearbyEntities(72, 72, 72)) { + Messaging.send(Bukkit.getConsoleSender(), "TEST ENTITY"); + if (entity instanceof Player && npcRegistry.isNPC(entity)) { + Messaging.send(Bukkit.getConsoleSender(), "YUP"); + final EntityPlayer entityplayer = ((CraftPlayer) player).getHandle(); + final EntityPlayer entitynpc = ((CraftPlayer) entity).getHandle(); + entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( + PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entitynpc)); + new BukkitRunnable() { + @Override + public void run() { + entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( + PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entitynpc)); + } + }.runTaskLater(CitizensAPI.getPlugin(), 2); + } + } + } + }.runTaskLater(CitizensAPI.getPlugin(), 30); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerQuit(PlayerQuitEvent event) { Editor.leave(event.getPlayer()); diff --git a/src/main/java/net/citizensnpcs/util/nms/PlayerlistTrackerEntry.java b/src/main/java/net/citizensnpcs/util/nms/PlayerlistTrackerEntry.java index 4e9a63a2a..81c06531f 100644 --- a/src/main/java/net/citizensnpcs/util/nms/PlayerlistTrackerEntry.java +++ b/src/main/java/net/citizensnpcs/util/nms/PlayerlistTrackerEntry.java @@ -2,6 +2,7 @@ package net.citizensnpcs.util.nms; import java.lang.reflect.Field; +import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_8_R2.Entity; import net.minecraft.server.v1_8_R2.EntityPlayer; @@ -9,6 +10,7 @@ import net.minecraft.server.v1_8_R2.EntityTrackerEntry; import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; public class PlayerlistTrackerEntry extends EntityTrackerEntry { public PlayerlistTrackerEntry(Entity entity, int i, int j, boolean flag) { @@ -20,7 +22,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry { } @Override - public void updatePlayer(EntityPlayer entityplayer) { + public void updatePlayer(final EntityPlayer entityplayer) { if (entityplayer != this.tracker && c(entityplayer)) { if (!this.trackedPlayers.contains(entityplayer) && ((entityplayer.u().getPlayerChunkMap().a(entityplayer, this.tracker.ae, this.tracker.ag)) || (this.tracker.attachedToPlayer))) { @@ -31,6 +33,13 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry { } entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, (EntityPlayer) this.tracker)); + new BukkitRunnable() { + @Override + public void run() { + entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( + PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, (EntityPlayer) tracker)); + } + }.runTaskLater(CitizensAPI.getPlugin(), 2); } } } From b20a0d4b4b8af6cd0eaacac584029b5b72bc0424 Mon Sep 17 00:00:00 2001 From: Morphan1 Date: Tue, 10 Mar 2015 03:19:12 -0400 Subject: [PATCH 2/4] Remove forgotten debug Oops --- src/main/java/net/citizensnpcs/EventListen.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index dd99daa25..44a900004 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -283,12 +283,9 @@ public class EventListen implements Listener { new BukkitRunnable() { @Override public void run() { - Messaging.send(Bukkit.getConsoleSender(), "TEST ENTITIES"); Player player = event.getPlayer(); for (Entity entity : player.getNearbyEntities(72, 72, 72)) { - Messaging.send(Bukkit.getConsoleSender(), "TEST ENTITY"); if (entity instanceof Player && npcRegistry.isNPC(entity)) { - Messaging.send(Bukkit.getConsoleSender(), "YUP"); final EntityPlayer entityplayer = ((CraftPlayer) player).getHandle(); final EntityPlayer entitynpc = ((CraftPlayer) entity).getHandle(); entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( From b0f7fb4348dce046d2b65dc638af7811db3ae5b9 Mon Sep 17 00:00:00 2001 From: Morphan1 Date: Tue, 10 Mar 2015 03:40:25 -0400 Subject: [PATCH 3/4] Make some minor adjustments --- src/main/java/net/citizensnpcs/EventListen.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 44a900004..74fe96e5e 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -283,24 +283,27 @@ public class EventListen implements Listener { new BukkitRunnable() { @Override public void run() { - Player player = event.getPlayer(); + final Player player = event.getPlayer(); + if (player == null || !player.isValid()) + return; for (Entity entity : player.getNearbyEntities(72, 72, 72)) { if (entity instanceof Player && npcRegistry.isNPC(entity)) { - final EntityPlayer entityplayer = ((CraftPlayer) player).getHandle(); final EntityPlayer entitynpc = ((CraftPlayer) entity).getHandle(); - entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( + NMS.sendPacket(player, new PacketPlayOutPlayerInfo( PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entitynpc)); new BukkitRunnable() { @Override public void run() { - entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( + if (!player.isValid()) + return; + NMS.sendPacket(player, new PacketPlayOutPlayerInfo( PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entitynpc)); } }.runTaskLater(CitizensAPI.getPlugin(), 2); } } } - }.runTaskLater(CitizensAPI.getPlugin(), 30); + }.runTaskLater(CitizensAPI.getPlugin(), 40); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) From d54c5ad8b4620bb1735719640160f38063fdaff1 Mon Sep 17 00:00:00 2001 From: Morphan1 Date: Tue, 10 Mar 2015 03:49:43 -0400 Subject: [PATCH 4/4] Increase radius limit --- src/main/java/net/citizensnpcs/EventListen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 74fe96e5e..3d761e829 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -286,7 +286,7 @@ public class EventListen implements Listener { final Player player = event.getPlayer(); if (player == null || !player.isValid()) return; - for (Entity entity : player.getNearbyEntities(72, 72, 72)) { + for (Entity entity : player.getNearbyEntities(200, 200, 200)) { if (entity instanceof Player && npcRegistry.isNPC(entity)) { final EntityPlayer entitynpc = ((CraftPlayer) entity).getHandle(); NMS.sendPacket(player, new PacketPlayOutPlayerInfo( @@ -303,7 +303,7 @@ public class EventListen implements Listener { } } } - }.runTaskLater(CitizensAPI.getPlugin(), 40); + }.runTaskLater(CitizensAPI.getPlugin(), 30); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)