Search in sources :

Example 1 with FileSystemSnapshotDatabase

use of com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase in project FastAsyncWorldEdit by IntellectualSites.

the class SnapshotCommands method list.

@Command(name = "list", desc = "List snapshots")
@CommandPermissions("worldedit.snapshots.list")
void list(Actor actor, World world, @ArgFlag(name = 'p', desc = "Page of results to return", def = "1") int page) throws WorldEditException, IOException {
    LocalConfiguration config = we.getConfiguration();
    checkSnapshotsConfigured(config);
    if (config.snapshotRepo != null) {
        legacy.list(actor, world, page);
        return;
    }
    List<Snapshot> snapshots;
    try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
        snapshots = snapshotStream.collect(toList());
    }
    if (!snapshots.isEmpty()) {
        actor.print(new SnapshotListBox(world.getName(), snapshots).create(page));
    } else {
        actor.print(Caption.of("worldedit.restore.none-for-specific-world", TextComponent.of(world.getName())));
        if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) {
            FileSystemSnapshotDatabase db = (FileSystemSnapshotDatabase) config.snapshotDatabase;
            Path root = db.getRoot();
            if (Files.isDirectory(root)) {
                WorldEdit.logger.info("No snapshots were found for world '" + world.getName() + "'; looked in " + root.toRealPath());
            } else {
                WorldEdit.logger.info("No snapshots were found for world '" + world.getName() + "'; " + root.toRealPath() + " is not a directory");
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Snapshot(com.sk89q.worldedit.world.snapshot.experimental.Snapshot) FileSystemSnapshotDatabase(com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 Snapshot (com.sk89q.worldedit.world.snapshot.experimental.Snapshot)1 FileSystemSnapshotDatabase (com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase)1 Path (java.nio.file.Path)1 Command (org.enginehub.piston.annotation.Command)1