Try to avoid async issues with entity trackers

This commit is contained in:
fullwall 2023-08-30 00:35:21 +08:00
parent 63ef3cdc73
commit 85e46c6324
6 changed files with 11 additions and 7 deletions

View File

@ -87,7 +87,8 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
}
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
|| !CitizensAPI.hasImplementation())
return;
final EntityPlayer entityplayer = lastUpdatedPlayer;
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());

View File

@ -35,8 +35,8 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
}
public void updateLastPlayer() {
if (tracker.isRemoved() || lastUpdatedPlayer == null
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
if (tracker.isRemoved() || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|| !CitizensAPI.hasImplementation())
return;
final ServerPlayer entityplayer = lastUpdatedPlayer;
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());

View File

@ -35,8 +35,8 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
}
public void updateLastPlayer() {
if (tracker.isRemoved() || lastUpdatedPlayer == null
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
if (tracker.isRemoved() || lastUpdatedPlayer == null || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|| !CitizensAPI.hasImplementation())
return;
final ServerPlayer entityplayer = lastUpdatedPlayer;
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());

View File

@ -58,7 +58,8 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
}
public void updateLastPlayer(ServerPlayer lastUpdatedPlayer) {
if (tracker.isRemoved() || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
if (tracker.isRemoved() || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|| !CitizensAPI.hasImplementation())
return;
final ServerPlayer entityplayer = lastUpdatedPlayer;
NPC npc = ((NPCHolder) tracker).getNPC();

View File

@ -59,7 +59,8 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
}
public void updateLastPlayer(ServerPlayer lastUpdatedPlayer) {
if (tracker.isRemoved() || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
if (tracker.isRemoved() || tracker.getBukkitEntity().getType() != EntityType.PLAYER
|| !CitizensAPI.hasImplementation())
return;
final ServerPlayer entityplayer = lastUpdatedPlayer;
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {

View File

@ -380,6 +380,7 @@ public class NMSImpl implements NMSBridge {
public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {
int viewDistance = -1;
ChunkMap chunkMap = null;
try {
if (entity instanceof Player) {
chunkMap = ((ServerChunkCache) getHandle(entity).level().getChunkSource()).chunkMap;