use of com.sk89q.worldedit.world.snapshot.experimental.Snapshot in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotCommands method use.
@Command(name = "use", desc = "Choose a snapshot to use")
@CommandPermissions("worldedit.snapshots.restore")
void use(Actor actor, World world, LocalSession session, @Arg(desc = "Snapshot to use") String name) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo != null) {
legacy.use(actor, world, session, name);
return;
}
// Want the latest snapshot?
if (name.equalsIgnoreCase("latest")) {
Snapshot snapshot;
try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream.findFirst().orElse(null);
}
if (snapshot != null) {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshot(null);
actor.print(Caption.of("worldedit.snapshot.use.newest"));
} else {
actor.print(Caption.of("worldedit.restore.none-for-world"));
}
} else {
URI uri = resolveSnapshotName(config, name);
Optional<Snapshot> snapshot = config.snapshotDatabase.getSnapshot(uri);
if (snapshot.isPresent()) {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshotExperimental(snapshot.get());
actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(name)));
} else {
actor.print(Caption.of("worldedit.restore.not-available"));
}
}
}
use of com.sk89q.worldedit.world.snapshot.experimental.Snapshot 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");
}
}
}
}
use of com.sk89q.worldedit.world.snapshot.experimental.Snapshot in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotCommands method after.
@Command(name = "after", desc = "Choose the nearest snapshot after a date")
@CommandPermissions("worldedit.snapshots.restore")
void after(Actor actor, World world, LocalSession session, @Arg(desc = "The soonest date that may be used") ZonedDateTime date) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo != null) {
legacy.after(actor, world, session, date);
return;
}
Snapshot snapshot;
try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream.findFirst().orElse(null);
}
if (snapshot == null) {
actor.print(Caption.of("worldedit.snapshot.none-after", TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))));
} else {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshotExperimental(snapshot);
actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(snapshot.getInfo().getDisplayName())));
}
}
use of com.sk89q.worldedit.world.snapshot.experimental.Snapshot in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotCommands method before.
@Command(name = "before", desc = "Choose the nearest snapshot before a date")
@CommandPermissions("worldedit.snapshots.restore")
void before(Actor actor, World world, LocalSession session, @Arg(desc = "The soonest date that may be used") ZonedDateTime date) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo != null) {
legacy.before(actor, world, session, date);
return;
}
Snapshot snapshot;
try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream.findFirst().orElse(null);
}
if (snapshot == null) {
actor.print(Caption.of("worldedit.snapshot.none-before", TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))));
} else {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshotExperimental(snapshot);
actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(snapshot.getInfo().getDisplayName())));
}
}
use of com.sk89q.worldedit.world.snapshot.experimental.Snapshot in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotUtilCommands method restore.
@Command(name = "restore", aliases = { "/restore" }, desc = "Restore the selection from a snapshot")
@Logging(REGION)
@CommandPermissions("worldedit.snapshots.restore")
public void restore(Actor actor, World world, LocalSession session, EditSession editSession, @Arg(name = "snapshot", desc = "The snapshot to restore", def = "") String snapshotName, // FAWE start - biome and entity restore
@Switch(name = 'b', desc = "If biomes should be restored. If restoring from pre-1.15 to 1.15+, biomes may not be " + "exactly the same due to 3D biomes.") boolean restoreBiomes, @Switch(name = 'e', desc = "If entities should be restored. Will cause issues with duplicate entities if all " + "original entities were not removed.") boolean restoreEntities) throws // FAWE end
WorldEditException, IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo != null) {
// FAWE start - biome and entity restore
legacy.restore(actor, world, session, editSession, snapshotName, restoreBiomes, restoreEntities);
// FAWE end
return;
}
Region region = session.getSelection(world);
Snapshot snapshot;
if (snapshotName != null) {
URI uri = resolveSnapshotName(config, snapshotName);
Optional<Snapshot> snapOpt = config.snapshotDatabase.getSnapshot(uri);
if (!snapOpt.isPresent()) {
actor.print(Caption.of("worldedit.restore.not-available"));
return;
}
snapshot = snapOpt.get();
} else {
snapshot = session.getSnapshotExperimental();
}
// No snapshot set?
if (snapshot == null) {
try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream.findFirst().orElse(null);
}
if (snapshot == null) {
actor.print(Caption.of("worldedit.restore.none-for-specific-world", TextComponent.of(world.getName())));
return;
}
}
actor.print(Caption.of("worldedit.restore.loaded", TextComponent.of(snapshot.getInfo().getDisplayName())));
try {
// Restore snapshot
// FAWE start - biome and entity restore
SnapshotRestore restore = new SnapshotRestore(snapshot, 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 {
snapshot.close();
} catch (IOException ignored) {
}
}
}
Aggregations