mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-29 06:05:17 +01:00
Backport to 1.8.8 too
This commit is contained in:
parent
9dbe312b44
commit
3c5ba43b92
@ -31,7 +31,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
public void updateLastPlayer() {
|
public void updateLastPlayer() {
|
||||||
if (lastUpdatedPlayer == null)
|
if (lastUpdatedPlayer == null)
|
||||||
return;
|
return;
|
||||||
Entity tracker = getTracker(this);
|
final Entity tracker = getTracker(this);
|
||||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
lastUpdatedPlayer = null;
|
lastUpdatedPlayer = null;
|
||||||
|
@ -30,6 +30,7 @@ import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerJump;
|
|||||||
import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerLook;
|
import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerLook;
|
||||||
import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerMove;
|
import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerMove;
|
||||||
import net.citizensnpcs.nms.v1_8_R3.util.PlayerNavigation;
|
import net.citizensnpcs.nms.v1_8_R3.util.PlayerNavigation;
|
||||||
|
import net.citizensnpcs.nms.v1_8_R3.util.PlayerlistTrackerEntry;
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
||||||
@ -42,6 +43,7 @@ import net.minecraft.server.v1_8_R3.AttributeInstance;
|
|||||||
import net.minecraft.server.v1_8_R3.Block;
|
import net.minecraft.server.v1_8_R3.Block;
|
||||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||||
import net.minecraft.server.v1_8_R3.DamageSource;
|
import net.minecraft.server.v1_8_R3.DamageSource;
|
||||||
|
import net.minecraft.server.v1_8_R3.DataWatcher;
|
||||||
import net.minecraft.server.v1_8_R3.Entity;
|
import net.minecraft.server.v1_8_R3.Entity;
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R3.EnumProtocolDirection;
|
import net.minecraft.server.v1_8_R3.EnumProtocolDirection;
|
||||||
@ -59,12 +61,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
private PlayerControllerJump controllerJump;
|
private PlayerControllerJump controllerJump;
|
||||||
private PlayerControllerLook controllerLook;
|
private PlayerControllerLook controllerLook;
|
||||||
private PlayerControllerMove controllerMove;
|
private PlayerControllerMove controllerMove;
|
||||||
private boolean isTracked = false;
|
|
||||||
private int jumpTicks = 0;
|
private int jumpTicks = 0;
|
||||||
private PlayerNavigation navigation;
|
private PlayerNavigation navigation;
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||||
private final SkinPacketTracker skinTracker;
|
private final SkinPacketTracker skinTracker;
|
||||||
|
private PlayerlistTrackerEntry trackerEntry;
|
||||||
private int updateCounter = 0;
|
private int updateCounter = 0;
|
||||||
|
|
||||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||||
@ -90,7 +92,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean a(EntityPlayer entityplayer) {
|
public boolean a(EntityPlayer entityplayer) {
|
||||||
if (npc != null && !isTracked) {
|
if (npc != null && trackerEntry == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return super.a(entityplayer);
|
return super.a(entityplayer);
|
||||||
@ -211,6 +213,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
return controllerMove;
|
return controllerMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataWatcher getDataWatcher() {
|
||||||
|
if (trackerEntry != null && trackerEntry.isUpdating()) {
|
||||||
|
trackerEntry.updateLastPlayer();
|
||||||
|
}
|
||||||
|
return super.getDataWatcher();
|
||||||
|
}
|
||||||
|
|
||||||
public NavigationAbstract getNavigation() {
|
public NavigationAbstract getNavigation() {
|
||||||
return navigation;
|
return navigation;
|
||||||
}
|
}
|
||||||
@ -352,8 +362,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTracked() {
|
public void setTracked(PlayerlistTrackerEntry trackerEntry) {
|
||||||
isTracked = true;
|
this.trackerEntry = trackerEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -772,7 +772,7 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
if (getHandle(player) instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,20 @@ package net.citizensnpcs.nms.v1_8_R3.util;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import net.citizensnpcs.Settings.Setting;
|
||||||
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC;
|
import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC;
|
||||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
import net.minecraft.server.v1_8_R3.Entity;
|
import net.minecraft.server.v1_8_R3.Entity;
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
||||||
|
|
||||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||||
|
private EntityPlayer lastUpdatedPlayer;
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, boolean flag) {
|
public PlayerlistTrackerEntry(Entity entity, int i, int j, boolean flag) {
|
||||||
super(entity, i, j, flag);
|
super(entity, i, j, flag);
|
||||||
}
|
}
|
||||||
@ -20,28 +24,35 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
this(getTracker(entry), getB(entry), getC(entry), getU(entry));
|
this(getTracker(entry), getB(entry), getC(entry), getU(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUpdating() {
|
||||||
|
return lastUpdatedPlayer != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLastPlayer() {
|
||||||
|
if (lastUpdatedPlayer == null)
|
||||||
|
return;
|
||||||
|
final Entity tracker = getTracker(this);
|
||||||
|
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||||
|
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
|
lastUpdatedPlayer = null;
|
||||||
|
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||||
|
return;
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
Entity tracker = getTracker(this);
|
lastUpdatedPlayer = entityplayer;
|
||||||
if (entityplayer != tracker && c(entityplayer)) {
|
|
||||||
if (!this.trackedPlayers.contains(entityplayer)
|
|
||||||
&& ((entityplayer.u().getPlayerChunkMap().a(entityplayer, tracker.ae, tracker.ag))
|
|
||||||
|| (tracker.attachedToPlayer))) {
|
|
||||||
if ((tracker instanceof SkinnableEntity)) {
|
|
||||||
SkinnableEntity skinnable = (SkinnableEntity) tracker;
|
|
||||||
|
|
||||||
Player player = skinnable.getBukkitEntity();
|
|
||||||
if (!entityplayer.getBukkitEntity().canSee(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
skinnable.getSkinTracker().updateViewer(entityplayer.getBukkitEntity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
|
lastUpdatedPlayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getB(EntityTrackerEntry entry) {
|
private static int getB(EntityTrackerEntry entry) {
|
||||||
|
Loading…
Reference in New Issue
Block a user