Search in sources :

Example 1 with ChunkStore

use of com.sk89q.worldedit.world.storage.ChunkStore in project FastAsyncWorldEdit by IntellectualSites.

the class Snapshot method getChunkStore.

/**
 * Get a chunk store.
 *
 * @return a chunk store
 * @throws IOException   if there is an error loading the chunk store
 * @throws DataException if there is an error loading the chunk store
 */
public ChunkStore getChunkStore() throws IOException, DataException {
    ChunkStore chunkStore = internalGetChunkStore();
    LOGGER.info("WorldEdit: Using " + chunkStore.getClass().getCanonicalName() + " for loading snapshot '" + file.getAbsolutePath() + "'");
    return chunkStore;
}
Also used : ChunkStore(com.sk89q.worldedit.world.storage.ChunkStore) ZippedMcRegionChunkStore(com.sk89q.worldedit.world.storage.ZippedMcRegionChunkStore) ZippedLegacyChunkStore(com.sk89q.worldedit.world.storage.ZippedLegacyChunkStore) FileLegacyChunkStore(com.sk89q.worldedit.world.storage.FileLegacyChunkStore) FileMcRegionChunkStore(com.sk89q.worldedit.world.storage.FileMcRegionChunkStore) TrueZipLegacyChunkStore(com.sk89q.worldedit.world.storage.TrueZipLegacyChunkStore) TrueZipMcRegionChunkStore(com.sk89q.worldedit.world.storage.TrueZipMcRegionChunkStore)

Example 2 with ChunkStore

use of com.sk89q.worldedit.world.storage.ChunkStore in project FastAsyncWorldEdit by IntellectualSites.

the class LegacySnapshotUtilCommands method restore.

// FAWE start - biome and entity restore
void restore(Actor actor, World world, LocalSession session, EditSession editSession, String snapshotName, boolean restoreBiomes, boolean restoreEntities) throws // FAWE end
WorldEditException {
    LocalConfiguration config = we.getConfiguration();
    Region region = session.getSelection(world);
    Snapshot snapshot;
    if (snapshotName != null) {
        try {
            snapshot = config.snapshotRepo.getSnapshot(snapshotName);
        } catch (InvalidSnapshotException e) {
            actor.print(Caption.of("worldedit.restore.not-available"));
            return;
        }
    } else {
        snapshot = session.getSnapshot();
    }
    // No snapshot set?
    if (snapshot == null) {
        try {
            snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName());
            if (snapshot == null) {
                actor.print(Caption.of("worldedit.restore.none-found-console"));
                // Okay, let's toss some debugging information!
                File dir = config.snapshotRepo.getDirectory();
                try {
                    WorldEdit.logger.info("WorldEdit found no snapshots: looked in: " + dir.getCanonicalPath());
                } catch (IOException e) {
                    WorldEdit.logger.info("WorldEdit found no snapshots: looked in " + "(NON-RESOLVABLE PATH - does it exist?): " + dir.getPath());
                }
                return;
            }
        } catch (MissingWorldException ex) {
            actor.print(Caption.of("worldedit.restore.none-for-world"));
            return;
        }
    }
    ChunkStore chunkStore;
    // Load chunk store
    try {
        chunkStore = snapshot.getChunkStore();
        actor.print(Caption.of("worldedit.restore.loaded", TextComponent.of(snapshot.getName())));
    } catch (DataException | IOException e) {
        actor.print(Caption.of("worldedit.restore.failed", TextComponent.of(e.getMessage())));
        return;
    }
    try {
        // Restore snapshot
        // FAWE start - biome and entity restore
        SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region, restoreBiomes, restoreEntities);
        // FAWE end
        restore.restore();
        if (restore.hadTotalFailure()) {
            String error = restore.getLastErrorMessage();
            if (!restore.getMissingChunks().isEmpty()) {
                actor.print(Caption.of("worldedit.restore.chunk-not-present"));
            } else if (error != null) {
                actor.print(Caption.of("worldedit.restore.block-place-failed"));
                actor.print(Caption.of("worldedit.restore.block-place-error", TextComponent.of(error)));
            } else {
                actor.print(Caption.of("worldedit.restore.chunk-load-failed"));
            }
        } else {
            actor.print(Caption.of("worldedit.restore.restored", TextComponent.of(restore.getMissingChunks().size()), TextComponent.of(restore.getErrorChunks().size())));
        }
    } finally {
        try {
            chunkStore.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.Snapshot) InvalidSnapshotException(com.sk89q.worldedit.world.snapshot.InvalidSnapshotException) DataException(com.sk89q.worldedit.world.DataException) SnapshotRestore(com.sk89q.worldedit.world.snapshot.SnapshotRestore) Region(com.sk89q.worldedit.regions.Region) IOException(java.io.IOException) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) File(java.io.File) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException) ChunkStore(com.sk89q.worldedit.world.storage.ChunkStore)

Aggregations

ChunkStore (com.sk89q.worldedit.world.storage.ChunkStore)2 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)1 Region (com.sk89q.worldedit.regions.Region)1 DataException (com.sk89q.worldedit.world.DataException)1 InvalidSnapshotException (com.sk89q.worldedit.world.snapshot.InvalidSnapshotException)1 Snapshot (com.sk89q.worldedit.world.snapshot.Snapshot)1 SnapshotRestore (com.sk89q.worldedit.world.snapshot.SnapshotRestore)1 FileLegacyChunkStore (com.sk89q.worldedit.world.storage.FileLegacyChunkStore)1 FileMcRegionChunkStore (com.sk89q.worldedit.world.storage.FileMcRegionChunkStore)1 MissingWorldException (com.sk89q.worldedit.world.storage.MissingWorldException)1 TrueZipLegacyChunkStore (com.sk89q.worldedit.world.storage.TrueZipLegacyChunkStore)1 TrueZipMcRegionChunkStore (com.sk89q.worldedit.world.storage.TrueZipMcRegionChunkStore)1 ZippedLegacyChunkStore (com.sk89q.worldedit.world.storage.ZippedLegacyChunkStore)1 ZippedMcRegionChunkStore (com.sk89q.worldedit.world.storage.ZippedMcRegionChunkStore)1 File (java.io.File)1 IOException (java.io.IOException)1