@Override public synchronized void saveChunk(int cx, int cz, World world) { if (world == null) return; boolean unloaded = false; if (!store.containsKey(world.getName() + "," + cx + "," + cz)) { List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs); for (Entity entity : tempSpawnedMobs) { if (!isEntityInChunk(entity, cx, cz, world)) continue; loadChunk(cx, cz, world); unloaded = true; break; } if (!unloaded) { List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets); for (Entity entity : tempSpawnedPets) { if (!isEntityInChunk(entity, cx, cz, world)) continue; loadChunk(cx, cz, world); unloaded = true; break; } } } if (!store.containsKey(world.getName() + "," + cx + "," + cz) && unloaded) { ChunkStore cStore = ChunkStoreFactory.getChunkStore(world, cx, cz); store.put(world.getName() + "," + cx + "," + cz, cStore); } if (store.containsKey(world.getName() + "," + cx + "," + cz)) { ChunkStore out = store.get(world.getName() + "," + cx + "," + cz); List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs); for (Entity entity : tempSpawnedMobs) { if (!isEntityInChunk(entity, cx, cz, world)) continue; out.addSpawnedMob(entity.getUniqueId()); } List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets); for (Entity entity : tempSpawnedPets) { if (!isEntityInChunk(entity, cx, cz, world)) continue; out.addSpawnedPet(entity.getUniqueId()); } if (!out.isDirty()) return; writeChunkStore(world, cx, cz, out); } }