Added support for restoring from backups (snapshots). Added /listsnapshots, //use, and //restore.
This commit is contained in:
@@ -1279,63 +1279,4 @@ public class EditSession {
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores a region from a backup.
|
||||
*
|
||||
* @param region
|
||||
* @param chunkStore
|
||||
*/
|
||||
public void restoreBackup(Region region, ChunkStore chunkStore)
|
||||
throws MaxChangedBlocksException {
|
||||
// TODO: Make this support non-cuboid regions
|
||||
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
|
||||
Map<BlockVector2D,ArrayList<Vector>> neededChunks =
|
||||
new LinkedHashMap<BlockVector2D,ArrayList<Vector>>();
|
||||
|
||||
// First, we need to group points by chunk so that we only need
|
||||
// to keep one chunk in memory at any given moment
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||
Vector pos = new Vector(x, y, z);
|
||||
BlockVector2D chunkPos = ChunkStore.toChunk(pos);
|
||||
|
||||
// Unidentified chunk
|
||||
if (!neededChunks.containsKey(chunkPos)) {
|
||||
neededChunks.put(chunkPos, new ArrayList<Vector>());
|
||||
}
|
||||
|
||||
neededChunks.get(chunkPos).add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now let's start restoring!
|
||||
for (Map.Entry<BlockVector2D,ArrayList<Vector>> entry :
|
||||
neededChunks.entrySet()) {
|
||||
BlockVector2D chunkPos = entry.getKey();
|
||||
Chunk chunk;
|
||||
|
||||
try {
|
||||
chunk = chunkStore.getChunk(chunkPos);
|
||||
// Good, the chunk could be at least loaded
|
||||
|
||||
// Now just copy blocks!
|
||||
for (Vector pos : entry.getValue()) {
|
||||
BaseBlock block = chunk.getBlock(pos);
|
||||
setBlock(pos, block);
|
||||
}
|
||||
} catch (DataException de) {
|
||||
// TODO: Error handling
|
||||
de.printStackTrace();
|
||||
} catch (IOException ioe) {
|
||||
// TODO: Error handling
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user