From 85e46c6324da9b9e7bf3e16b2d5684f3b9751166 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 30 Aug 2023 00:35:21 +0800 Subject: [PATCH] Try to avoid async issues with entity trackers --- .../net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java | 3 ++- .../net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java | 4 ++-- .../net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java | 4 ++-- .../citizensnpcs/nms/v1_19_R3/util/CitizensEntityTracker.java | 3 ++- .../citizensnpcs/nms/v1_20_R1/util/CitizensEntityTracker.java | 3 ++- .../main/java/net/citizensnpcs/nms/v1_20_R1/util/NMSImpl.java | 1 + 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java index 6d1d4d437..31242dfd9 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/PlayerlistTracker.java @@ -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()); diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java index 6ebf43ee3..70a514b66 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/PlayerlistTracker.java @@ -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()); diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java index c2ffa94d2..bfd8804e3 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerlistTracker.java @@ -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()); diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/CitizensEntityTracker.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/CitizensEntityTracker.java index e7a9f8e4a..cfdc971c9 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/CitizensEntityTracker.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/CitizensEntityTracker.java @@ -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(); diff --git a/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/CitizensEntityTracker.java b/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/CitizensEntityTracker.java index 57946d835..956882c42 100644 --- a/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/CitizensEntityTracker.java +++ b/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/CitizensEntityTracker.java @@ -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(), () -> { diff --git a/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/NMSImpl.java b/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/NMSImpl.java index fac14665f..a30164562 100644 --- a/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/NMSImpl.java +++ b/v1_20_R1/src/main/java/net/citizensnpcs/nms/v1_20_R1/util/NMSImpl.java @@ -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;