Skip to content

Commit

Permalink
Temporary workaround for exception spam
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 14, 2024
1 parent 6bcae0f commit 74df481
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions main/src/main/java/net/citizensnpcs/EventListen.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,24 @@ public void onChunkUnload(ChunkUnloadEvent event) {
new double[] { (event.getChunk().getX() << 4) - 0.5, 0, (event.getChunk().getZ() << 4) - 0.5 },
new double[] { (event.getChunk().getX() + 1 << 4) + 0.5, 256,
(event.getChunk().getZ() + 1 << 4) + 0.5 }));
for (Entity entity : event.getChunk().getEntities()) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity);
// XXX npc#isSpawned() checks valid status which is now inconsistent on chunk unload
// between different server software so check for npc.getEntity() == null instead.
if (npc == null || npc.getEntity() == null || toDespawn.contains(npc))
continue;
if (SUPPORTS_UNLOAD_CHUNK_ENTITIES == null) {
try {
event.getChunk().getEntities();
SUPPORTS_UNLOAD_CHUNK_ENTITIES = true;
} catch (Throwable t) {
SUPPORTS_UNLOAD_CHUNK_ENTITIES = false;
}
}
if (SUPPORTS_UNLOAD_CHUNK_ENTITIES) {
for (Entity entity : event.getChunk().getEntities()) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity);
// XXX npc#isSpawned() checks valid status which is now inconsistent on chunk unload
// between different server software so check for npc.getEntity() == null instead.
if (npc == null || npc.getEntity() == null || toDespawn.contains(npc))
continue;

toDespawn.add(npc);
toDespawn.add(npc);
}
}
if (toDespawn.isEmpty())
return;
Expand Down Expand Up @@ -956,4 +966,6 @@ private void unloadNPCs(ChunkEvent event, List<NPC> toDespawn) {
}

private static boolean SUPPORT_STOP_USE_ITEM = true;

private static Boolean SUPPORTS_UNLOAD_CHUNK_ENTITIES;
}

0 comments on commit 74df481

Please sign in to comment.