2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.config.BBC;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.world.DataException;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
|
|
|
|
import com.sk89q.worldedit.world.snapshot.Snapshot;
|
|
|
|
import com.sk89q.worldedit.world.snapshot.SnapshotRestore;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.world.storage.ChunkStore;
|
|
|
|
import com.sk89q.worldedit.world.storage.MissingWorldException;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
|
|
|
|
|
|
|
|
@Command(aliases = {}, desc = "[More Info](http://wiki.sk89q.com/wiki/WorldEdit/Snapshots)")
|
2014-04-03 02:08:50 +00:00
|
|
|
public class SnapshotUtilCommands {
|
|
|
|
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
|
|
|
|
|
|
|
private final WorldEdit we;
|
|
|
|
|
|
|
|
public SnapshotUtilCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"restore", "/restore"},
|
2014-04-03 02:08:50 +00:00
|
|
|
usage = "[snapshot]",
|
|
|
|
desc = "Restore the selection from a snapshot",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.snapshots.restore")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void restore(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
LocalConfiguration config = we.getConfiguration();
|
|
|
|
|
|
|
|
if (config.snapshotRepo == null) {
|
|
|
|
player.printError("Snapshot/backup restore is not configured.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Region region = session.getSelection(player.getWorld());
|
|
|
|
Snapshot snapshot;
|
|
|
|
|
|
|
|
if (args.argsLength() > 0) {
|
|
|
|
try {
|
|
|
|
snapshot = config.snapshotRepo.getSnapshot(args.getString(0));
|
|
|
|
} catch (InvalidSnapshotException e) {
|
|
|
|
player.printError("That snapshot does not exist or is not available.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
snapshot = session.getSnapshot();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No snapshot set?
|
|
|
|
if (snapshot == null) {
|
|
|
|
try {
|
|
|
|
snapshot = config.snapshotRepo.getDefaultSnapshot(player.getWorld().getName());
|
|
|
|
|
|
|
|
if (snapshot == null) {
|
|
|
|
player.printError("No snapshots were found. See console for details.");
|
|
|
|
|
|
|
|
// Okay, let's toss some debugging information!
|
|
|
|
File dir = config.snapshotRepo.getDirectory();
|
|
|
|
|
|
|
|
try {
|
2018-08-12 14:03:07 +00:00
|
|
|
logger.info("FAWE found no snapshots: looked in: "
|
2014-04-03 02:08:50 +00:00
|
|
|
+ dir.getCanonicalPath());
|
|
|
|
} catch (IOException e) {
|
2018-08-12 14:03:07 +00:00
|
|
|
logger.info("FAWE found no snapshots: looked in "
|
2014-04-03 02:08:50 +00:00
|
|
|
+ "(NON-RESOLVABLE PATH - does it exist?): "
|
|
|
|
+ dir.getPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (MissingWorldException ex) {
|
|
|
|
player.printError("No snapshots were found for this world.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChunkStore chunkStore = null;
|
|
|
|
|
|
|
|
// Load chunk store
|
|
|
|
try {
|
|
|
|
chunkStore = snapshot.getChunkStore();
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.SNAPSHOT_LOADED.send(player, snapshot.getName());
|
|
|
|
} catch (DataException e) {
|
|
|
|
player.printError("Failed to load snapshot: " + e.getMessage());
|
|
|
|
return;
|
|
|
|
} catch (IOException e) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.printError("Failed to load snapshot: " + e.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Restore snapshot
|
|
|
|
SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region);
|
|
|
|
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
|
|
|
|
|
|
|
|
restore.restore();
|
|
|
|
|
|
|
|
if (restore.hadTotalFailure()) {
|
|
|
|
String error = restore.getLastErrorMessage();
|
|
|
|
if (error != null) {
|
|
|
|
player.printError("Errors prevented any blocks from being restored.");
|
|
|
|
player.printError("Last error: " + error);
|
|
|
|
} else {
|
|
|
|
player.printError("No chunks could be loaded. (Bad archive?)");
|
|
|
|
}
|
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
player.print(BBC.getPrefix() + String.format("Restored; %d "
|
|
|
|
+ "missing chunks and %d other errors.",
|
2014-04-03 02:08:50 +00:00
|
|
|
restore.getMissingChunks().size(),
|
|
|
|
restore.getErrorChunks().size()));
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
chunkStore.close();
|
2014-07-29 18:04:04 +00:00
|
|
|
} catch (IOException ignored) {
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|