mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Reduce NPCSeenByPlayerEvent allocations
This commit is contained in:
parent
c2e4f93416
commit
3571c05d9d
@ -31,7 +31,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
Entity tracker = getTracker(this);
|
Entity tracker = getTracker(this);
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!trackedPlayers.contains(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -16,7 +16,6 @@ import net.citizensnpcs.Settings.Setting;
|
|||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC;
|
|
||||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
import net.minecraft.server.v1_11_R1.Entity;
|
import net.minecraft.server.v1_11_R1.Entity;
|
||||||
@ -26,12 +25,15 @@ import net.minecraft.server.v1_11_R1.EntityTrackerEntry;
|
|||||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||||
private Entity tracker;
|
private Entity tracker;
|
||||||
|
|
||||||
|
private Map<EntityPlayer, Boolean> trackingMap;
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
||||||
super(entity, i, j, k, flag);
|
super(entity, i, j, k, flag);
|
||||||
tracker = getTracker(this);
|
tracker = getTracker(this);
|
||||||
if (TRACKING_MAP_SETTER != null) {
|
if (TRACKING_MAP_SETTER != null) {
|
||||||
try {
|
try {
|
||||||
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
||||||
|
trackingMap = delegate;
|
||||||
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Map<EntityPlayer, Boolean> delegate() {
|
protected Map<EntityPlayer, Boolean> delegate() {
|
||||||
@ -78,6 +80,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTracked(EntityPlayer player) {
|
||||||
|
return trackingMap != null ? trackingMap.containsKey(player) : trackedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||||
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
@ -93,16 +99,15 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
// prevent updates to NPC "viewers"
|
if (!tracker.dead && !isTracked(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
if (entityplayer instanceof EntityHumanNPC)
|
|
||||||
return;
|
|
||||||
if (tracker instanceof NPCHolder) {
|
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (entityplayer instanceof NPCHolder)
|
||||||
|
return;
|
||||||
super.updatePlayer(entityplayer);
|
super.updatePlayer(entityplayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +26,15 @@ import net.minecraft.server.v1_12_R1.EntityTrackerEntry;
|
|||||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||||
private final Entity tracker;
|
private final Entity tracker;
|
||||||
|
|
||||||
|
private Map<EntityPlayer, Boolean> trackingMap;
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
||||||
super(entity, i, j, k, flag);
|
super(entity, i, j, k, flag);
|
||||||
this.tracker = getTracker(this);
|
this.tracker = getTracker(this);
|
||||||
if (TRACKING_MAP_SETTER != null) {
|
if (TRACKING_MAP_SETTER != null) {
|
||||||
try {
|
try {
|
||||||
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
||||||
|
trackingMap = delegate;
|
||||||
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Map<EntityPlayer, Boolean> delegate() {
|
protected Map<EntityPlayer, Boolean> delegate() {
|
||||||
@ -78,6 +81,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTracked(EntityPlayer player) {
|
||||||
|
return trackingMap != null ? trackingMap.containsKey(player) : trackedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||||
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
if (lastUpdatedPlayer == null || tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
@ -93,7 +100,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.dead && !isTracked(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -26,6 +26,7 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutAnimation;
|
|||||||
|
|
||||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||||
private final Entity tracker;
|
private final Entity tracker;
|
||||||
|
private Map<EntityPlayer, Boolean> trackingMap;
|
||||||
|
|
||||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
||||||
super(entity, i, j, k, flag);
|
super(entity, i, j, k, flag);
|
||||||
@ -33,6 +34,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
if (TRACKING_MAP_SETTER != null) {
|
if (TRACKING_MAP_SETTER != null) {
|
||||||
try {
|
try {
|
||||||
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
||||||
|
trackingMap = delegate;
|
||||||
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Map<EntityPlayer, Boolean> delegate() {
|
protected Map<EntityPlayer, Boolean> delegate() {
|
||||||
@ -79,6 +81,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTracked(EntityPlayer player) {
|
||||||
|
return trackingMap != null ? trackingMap.containsKey(player) : trackedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
@ -97,7 +103,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.dead && !isTracked(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -27,6 +27,7 @@ import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker;
|
|||||||
|
|
||||||
public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
||||||
private final Entity tracker;
|
private final Entity tracker;
|
||||||
|
private Map<EntityPlayer, Boolean> trackingMap;
|
||||||
|
|
||||||
public PlayerlistTracker(PlayerChunkMap map, Entity entity, int i, int j, boolean flag) {
|
public PlayerlistTracker(PlayerChunkMap map, Entity entity, int i, int j, boolean flag) {
|
||||||
map.super(entity, i, j, flag);
|
map.super(entity, i, j, flag);
|
||||||
@ -34,6 +35,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
if (TRACKING_MAP_SETTER != null) {
|
if (TRACKING_MAP_SETTER != null) {
|
||||||
try {
|
try {
|
||||||
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
||||||
|
trackingMap = delegate;
|
||||||
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Map<EntityPlayer, Boolean> delegate() {
|
protected Map<EntityPlayer, Boolean> delegate() {
|
||||||
@ -80,6 +82,10 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
this(map, getTracker(entry), getTrackingDistance(entry), getD(entry), getE(entry));
|
this(map, getTracker(entry), getTrackingDistance(entry), getD(entry), getE(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTracked(EntityPlayer player) {
|
||||||
|
return trackingMap != null ? trackingMap.containsKey(player) : trackedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
@ -97,7 +103,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.dead && !isTracked(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -27,6 +27,7 @@ import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker;
|
|||||||
|
|
||||||
public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
||||||
private final Entity tracker;
|
private final Entity tracker;
|
||||||
|
private Map<EntityPlayer, Boolean> trackingMap;
|
||||||
|
|
||||||
public PlayerlistTracker(PlayerChunkMap map, Entity entity, int i, int j, boolean flag) {
|
public PlayerlistTracker(PlayerChunkMap map, Entity entity, int i, int j, boolean flag) {
|
||||||
map.super(entity, i, j, flag);
|
map.super(entity, i, j, flag);
|
||||||
@ -34,6 +35,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
if (TRACKING_MAP_SETTER != null) {
|
if (TRACKING_MAP_SETTER != null) {
|
||||||
try {
|
try {
|
||||||
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
||||||
|
trackingMap = delegate;
|
||||||
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Map<EntityPlayer, Boolean> delegate() {
|
protected Map<EntityPlayer, Boolean> delegate() {
|
||||||
@ -80,6 +82,10 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
this(map, getTracker(entry), getTrackingDistance(entry), getD(entry), getE(entry));
|
this(map, getTracker(entry), getTrackingDistance(entry), getD(entry), getE(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTracked(EntityPlayer player) {
|
||||||
|
return trackingMap != null ? trackingMap.containsKey(player) : trackedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
@ -97,7 +103,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.dead && !isTracked(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -27,6 +27,7 @@ import net.minecraft.server.v1_16_R3.PlayerChunkMap.EntityTracker;
|
|||||||
|
|
||||||
public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
||||||
private final Entity tracker;
|
private final Entity tracker;
|
||||||
|
private Map<EntityPlayer, Boolean> trackingMap;
|
||||||
|
|
||||||
public PlayerlistTracker(PlayerChunkMap map, Entity entity, int i, int j, boolean flag) {
|
public PlayerlistTracker(PlayerChunkMap map, Entity entity, int i, int j, boolean flag) {
|
||||||
map.super(entity, i, j, flag);
|
map.super(entity, i, j, flag);
|
||||||
@ -34,6 +35,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
if (TRACKING_MAP_SETTER != null) {
|
if (TRACKING_MAP_SETTER != null) {
|
||||||
try {
|
try {
|
||||||
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
Map<EntityPlayer, Boolean> delegate = (Map<EntityPlayer, Boolean>) TRACKING_MAP_GETTER.invoke(this);
|
||||||
|
trackingMap = delegate;
|
||||||
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
TRACKING_MAP_SETTER.invoke(this, new ForwardingMap<EntityPlayer, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Map<EntityPlayer, Boolean> delegate() {
|
protected Map<EntityPlayer, Boolean> delegate() {
|
||||||
@ -80,6 +82,10 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
this(map, getTracker(entry), getTrackingDistance(entry), getD(entry), getE(entry));
|
this(map, getTracker(entry), getTrackingDistance(entry), getD(entry), getE(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTracked(EntityPlayer player) {
|
||||||
|
return trackingMap != null ? trackingMap.containsKey(player) : trackedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
public void updateLastPlayer(EntityPlayer lastUpdatedPlayer) {
|
||||||
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
if (tracker.dead || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||||
return;
|
return;
|
||||||
@ -97,7 +103,7 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.dead && !isTracked(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -52,7 +52,7 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.isRemoved() && !seenBy.contains(entityplayer.connection) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
REQUIRES_SYNC = Util.callEventPossiblySync(event, REQUIRES_SYNC);
|
REQUIRES_SYNC = Util.callEventPossiblySync(event, REQUIRES_SYNC);
|
||||||
|
@ -52,7 +52,7 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlayer(final ServerPlayer entityplayer) {
|
public void updatePlayer(final ServerPlayer entityplayer) {
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.isRemoved() && !seenBy.contains(entityplayer.connection) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
REQUIRES_SYNC = Util.callEventPossiblySync(event, REQUIRES_SYNC);
|
REQUIRES_SYNC = Util.callEventPossiblySync(event, REQUIRES_SYNC);
|
||||||
|
@ -79,7 +79,7 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
|||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.isRemoved() && !seenBy.contains(entityplayer.connection) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
REQUIRES_SYNC = Util.callEventPossiblySync(event, REQUIRES_SYNC);
|
REQUIRES_SYNC = Util.callEventPossiblySync(event, REQUIRES_SYNC);
|
||||||
|
@ -79,7 +79,7 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
|
|||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!tracker.isRemoved() && !seenBy.contains(entityplayer.connection) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
if (REQUIRES_SYNC == null) {
|
if (REQUIRES_SYNC == null) {
|
||||||
REQUIRES_SYNC = !Bukkit.isPrimaryThread();
|
REQUIRES_SYNC = !Bukkit.isPrimaryThread();
|
||||||
|
@ -55,7 +55,7 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
|||||||
// prevent updates to NPC "viewers"
|
// prevent updates to NPC "viewers"
|
||||||
if (entityplayer instanceof EntityHumanNPC)
|
if (entityplayer instanceof EntityHumanNPC)
|
||||||
return;
|
return;
|
||||||
if (tracker instanceof NPCHolder) {
|
if (!trackedPlayers.contains(entityplayer) && tracker instanceof NPCHolder) {
|
||||||
NPC npc = ((NPCHolder) tracker).getNPC();
|
NPC npc = ((NPCHolder) tracker).getNPC();
|
||||||
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user