Search in sources :

Example 1 with MissingWorldException

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

the class SnapshotRepository method getSnapshots.

/**
 * Get a list of snapshots in a directory. The newest snapshot is
 * near the top of the array.
 *
 * @param newestFirst true to get the newest first
 * @return a list of snapshots
 */
public List<Snapshot> getSnapshots(boolean newestFirst, String worldName) throws MissingWorldException {
    FilenameFilter filter = (dir, name) -> {
        File f = new File(dir, name);
        return isValidSnapshot(f);
    };
    File[] snapshotFiles = dir.listFiles();
    if (snapshotFiles == null) {
        throw new MissingWorldException(worldName);
    }
    List<Snapshot> list = new ArrayList<>(snapshotFiles.length);
    for (File file : snapshotFiles) {
        if (isValidSnapshot(file)) {
            Snapshot snapshot = new Snapshot(this, file.getName());
            if (snapshot.containsWorld(worldName)) {
                detectDate(snapshot);
                list.add(snapshot);
            }
        } else if (file.isDirectory() && file.getName().equalsIgnoreCase(worldName)) {
            for (String name : file.list(filter)) {
                Snapshot snapshot = new Snapshot(this, file.getName() + "/" + name);
                detectDate(snapshot);
                list.add(snapshot);
            }
        }
    }
    if (newestFirst) {
        list.sort(Collections.reverseOrder());
    } else {
        Collections.sort(list);
    }
    return list;
}
Also used : FilenameFilter(java.io.FilenameFilter) List(java.util.List) Calendar(java.util.Calendar) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException) Locale(java.util.Locale) ZonedDateTime(java.time.ZonedDateTime) ZoneOffset(java.time.ZoneOffset) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) File(java.io.File) ArrayList(java.util.ArrayList) FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) File(java.io.File) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException)

Example 2 with MissingWorldException

use of com.sk89q.worldedit.world.storage.MissingWorldException 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)

Example 3 with MissingWorldException

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

the class LegacySnapshotCommands method before.

void before(Actor actor, World world, LocalSession session, ZonedDateTime date) {
    LocalConfiguration config = we.getConfiguration();
    try {
        Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date, world.getName());
        if (snapshot == null) {
            actor.print(Caption.of("worldedit.snapshot.none-before", TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))));
        } else {
            session.setSnapshot(snapshot);
            actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName())));
        }
    } catch (MissingWorldException ex) {
        actor.print(Caption.of("worldedit.restore.none-for-world"));
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.Snapshot) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException)

Example 4 with MissingWorldException

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

the class LegacySnapshotCommands method after.

void after(Actor actor, World world, LocalSession session, ZonedDateTime date) {
    LocalConfiguration config = we.getConfiguration();
    try {
        Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, world.getName());
        if (snapshot == null) {
            actor.print(Caption.of("worldedit.snapshot.none-after", TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))));
        } else {
            session.setSnapshot(snapshot);
            actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName())));
        }
    } catch (MissingWorldException ex) {
        actor.print(Caption.of("worldedit.restore.none-for-world"));
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.Snapshot) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException)

Example 5 with MissingWorldException

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

the class LegacySnapshotCommands method use.

void use(Actor actor, World world, LocalSession session, String name) {
    LocalConfiguration config = we.getConfiguration();
    // Want the latest snapshot?
    if (name.equalsIgnoreCase("latest")) {
        try {
            Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName());
            if (snapshot != null) {
                session.setSnapshot(null);
                actor.print(Caption.of("worldedit.snapshot.use.newest"));
            } else {
                actor.print(Caption.of("worldedit.restore.none-found"));
            }
        } catch (MissingWorldException ex) {
            actor.print(Caption.of("worldedit.restore.none-for-world"));
        }
    } else {
        try {
            session.setSnapshot(config.snapshotRepo.getSnapshot(name));
            actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(name)));
        } catch (InvalidSnapshotException e) {
            actor.print(Caption.of("worldedit.restore.not-available"));
        }
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.Snapshot) InvalidSnapshotException(com.sk89q.worldedit.world.snapshot.InvalidSnapshotException) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException)

Aggregations

MissingWorldException (com.sk89q.worldedit.world.storage.MissingWorldException)7 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)6 Snapshot (com.sk89q.worldedit.world.snapshot.Snapshot)6 File (java.io.File)3 InvalidSnapshotException (com.sk89q.worldedit.world.snapshot.InvalidSnapshotException)2 IOException (java.io.IOException)2 Region (com.sk89q.worldedit.regions.Region)1 DataException (com.sk89q.worldedit.world.DataException)1 SnapshotRestore (com.sk89q.worldedit.world.snapshot.SnapshotRestore)1 ChunkStore (com.sk89q.worldedit.world.storage.ChunkStore)1 FilenameFilter (java.io.FilenameFilter)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Nullable (javax.annotation.Nullable)1