Fix NPE in ChunkUnloadEvent

fixes #5133 fixes #5118
This commit is contained in:
nossr50 2025-03-17 14:21:25 -07:00
parent 1005b29e96
commit 82af006ea4
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,5 @@
Version 2.2.034
Fixed a rare edge case where null entities during chunk unload would cause a NullPointerException and potentially lead to server instability
Fixed bug where arrow would award archery xp after a crossbow trickshot bounce
Version 2.2.033

View File

@ -15,9 +15,18 @@ public class ChunkListener implements Listener {
public void onChunkUnload(ChunkUnloadEvent event) {
final Chunk unloadingChunk = event.getChunk();
Arrays.stream(unloadingChunk.getEntities())
.filter(entity -> entity instanceof LivingEntity)
.map(entity -> (LivingEntity) entity)
.forEach(livingEntity -> mcMMO.getTransientEntityTracker().removeTrackedEntity(livingEntity));
// Avoid processing if chunk is null or unloaded
if (unloadingChunk == null || !unloadingChunk.isLoaded() || unloadingChunk.getEntities() == null) {
return;
}
try {
Arrays.stream(unloadingChunk.getEntities())
.filter(entity -> entity instanceof LivingEntity)
.map(entity -> (LivingEntity) entity)
.forEach(livingEntity -> mcMMO.getTransientEntityTracker().removeTrackedEntity(livingEntity));
} catch (Exception ex) {
mcMMO.p.getLogger().warning("Caught exception during chunk unload event processing: " + ex.getMessage());
}
}
}