@Override public synchronized void setTrue(int x, int y, int z, World world) { if (world == null) return; int cx = x / 16; int cz = z / 16; int ix = Math.abs(x) % 16; int iz = Math.abs(z) % 16; String key = world.getName() + "," + cx + "," + cz; if (!store.containsKey(key)) { loadChunk(cx, cz, world); } ChunkStore cStore = store.get(key); if (cStore == null) { cStore = ChunkStoreFactory.getChunkStore(world, cx, cz); store.put(key, cStore); } cStore.setTrue(ix, y, iz); }
@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); } }