|
@@ -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());
|
|
|
+ }
|
|
|
}
|
|
|
}
|