mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-26 11:07:59 +01:00
Merge pull request #267 from Morphan1/master
Improve tablist removal and skin updating
This commit is contained in:
commit
db762b650e
@ -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() {
|
||||
final Player player = event.getPlayer();
|
||||
if (player == null || !player.isValid())
|
||||
return;
|
||||
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(
|
||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entitynpc));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!player.isValid())
|
||||
return;
|
||||
NMS.sendPacket(player, 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());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user