protected byte[] loadCompressedChunk(Vector3i chunkPos) { if (isStoreChunksInZips()) { return loadChunkZip(chunkPos); } else { Path chunkPath = storagePathProvider.getChunkPath(chunkPos); if (Files.isRegularFile(chunkPath)) { try { return Files.readAllBytes(chunkPath); } catch (IOException e) { logger.error("Failed to load chunk {}", chunkPos, e); } } } return null; }
@Override public ChunkStore loadChunkStore(Vector3i chunkPos) { byte[] chunkData = loadCompressedChunk(chunkPos); ChunkStore store = null; if (chunkData != null) { ByteArrayInputStream bais = new ByteArrayInputStream(chunkData); try (GZIPInputStream gzipIn = new GZIPInputStream(bais)) { EntityData.ChunkStore storeData = EntityData.ChunkStore.parseFrom(gzipIn); store = new ChunkStoreInternal(storeData, entityManager, blockManager, biomeManager, extraDataManager); } catch (IOException e) { logger.error("Failed to read existing saved chunk {}", chunkPos); } } return store; }
@Override protected EntityData.PlayerStore loadPlayerStoreData(String playerId) { EntityData.PlayerStore disposedUnsavedPlayer = unloadedAndUnsavedPlayerMap.get(playerId); if (disposedUnsavedPlayer != null) { return disposedUnsavedPlayer; } EntityData.PlayerStore disposedSavingPlayer = unloadedAndSavingPlayerMap.get(playerId); if (disposedSavingPlayer != null) { return disposedSavingPlayer; } worldDirectoryReadLock.lock(); try { return super.loadPlayerStoreData(playerId); } finally { worldDirectoryReadLock.unlock(); } }
protected void deactivateOrDestroyEntityRecursive(EntityRef entity) { if (entity.isActive()) { for (EntityRef ownedEntity : helper.listOwnedEntities(entity)) { if (!ownedEntity.isAlwaysRelevant()) { if (!ownedEntity.isPersistent()) { // TODO check if destroy is recursive ownedEntity.destroy(); } else { deactivateOrDestroyEntityRecursive(ownedEntity); } } } getEntityManager().deactivateForStorage(entity); } }
protected Collection<EntityRef> getEntitiesOfChunk(Chunk chunk) { List<EntityRef> entitiesToStore = Lists.newArrayList(); AABB aabb = chunk.getAABB(); for (EntityRef entity : getEntityManager().getEntitiesWith(LocationComponent.class)) { if (!entity.getOwner().exists() && !entity.isAlwaysRelevant() && !entity.hasComponent(ClientComponent.class)) { LocationComponent loc = entity.getComponent(LocationComponent.class); if (loc != null) { if (aabb.contains(loc.getWorldPosition())) { entitiesToStore.add(entity); } } } } return entitiesToStore; }
@Override public PlayerStore loadPlayerStore(String playerId) { EntityData.PlayerStore store = loadPlayerStoreData(playerId); if (store != null) { return new PlayerStoreInternal(playerId, store, entityManager); } return new PlayerStoreInternal(playerId, entityManager); }
@Override protected byte[] loadCompressedChunk(Vector3i chunkPos) { CompressedChunkBuilder disposedUnsavedChunk = unloadedAndUnsavedChunkMap.get(chunkPos); if (disposedUnsavedChunk != null) { return disposedUnsavedChunk.buildEncodedChunk(); } CompressedChunkBuilder disposedSavingChunk = unloadedAndSavingChunkMap.get(chunkPos); if (disposedSavingChunk != null) { return disposedSavingChunk.buildEncodedChunk(); } worldDirectoryReadLock.lock(); try { return super.loadCompressedChunk(chunkPos); } finally { worldDirectoryReadLock.unlock(); } }