mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Snapshot restore now obeys masks again.
This commit is contained in:
parent
803b4df72e
commit
1746dd2e1a
@ -140,10 +140,10 @@ public class SnapshotUtilCommands {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Restore snapshot
|
// Restore snapshot
|
||||||
SnapshotRestore restore = new SnapshotRestore(chunkStore, region);
|
SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region);
|
||||||
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
|
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
|
||||||
|
|
||||||
restore.restore(editSession);
|
restore.restore();
|
||||||
|
|
||||||
if (restore.hadTotalFailure()) {
|
if (restore.hadTotalFailure()) {
|
||||||
String error = restore.getLastErrorMessage();
|
String error = restore.getLastErrorMessage();
|
||||||
|
@ -47,12 +47,16 @@ public class SnapshotRestore {
|
|||||||
/**
|
/**
|
||||||
* Store a list of chunks that are needed and the points in them.
|
* Store a list of chunks that are needed and the points in them.
|
||||||
*/
|
*/
|
||||||
private Map<BlockVector2D, ArrayList<Vector>> neededChunks =
|
private final Map<BlockVector2D, ArrayList<Vector>> neededChunks =
|
||||||
new LinkedHashMap<BlockVector2D, ArrayList<Vector>>();
|
new LinkedHashMap<BlockVector2D, ArrayList<Vector>>();
|
||||||
/**
|
/**
|
||||||
* Chunk store.
|
* Chunk store.
|
||||||
*/
|
*/
|
||||||
private ChunkStore chunkStore;
|
private final ChunkStore chunkStore;
|
||||||
|
/**
|
||||||
|
* Edit session.
|
||||||
|
*/
|
||||||
|
private final EditSession editSession;
|
||||||
/**
|
/**
|
||||||
* Count of the number of missing chunks.
|
* Count of the number of missing chunks.
|
||||||
*/
|
*/
|
||||||
@ -69,11 +73,13 @@ public class SnapshotRestore {
|
|||||||
/**
|
/**
|
||||||
* Construct the snapshot restore operation.
|
* Construct the snapshot restore operation.
|
||||||
*
|
*
|
||||||
* @param chunkStore
|
* @param chunkStore The {@link ChunkStore} to restore from
|
||||||
* @param region
|
* @param editSession The {@link EditSession} to restore to
|
||||||
|
* @param region The {@link Region} to restore to
|
||||||
*/
|
*/
|
||||||
public SnapshotRestore(ChunkStore chunkStore, Region region) {
|
public SnapshotRestore(ChunkStore chunkStore, EditSession editSession, Region region) {
|
||||||
this.chunkStore = chunkStore;
|
this.chunkStore = chunkStore;
|
||||||
|
this.editSession = editSession;
|
||||||
|
|
||||||
if (region instanceof CuboidRegion) {
|
if (region instanceof CuboidRegion) {
|
||||||
findNeededCuboidChunks(region);
|
findNeededCuboidChunks(region);
|
||||||
@ -83,9 +89,9 @@ public class SnapshotRestore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find needed chunks in the cuboid of the region.
|
* Find needed chunks in the axis-aligned bounding box of the region.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region The {@link Region} to iterate
|
||||||
*/
|
*/
|
||||||
private void findNeededCuboidChunks(Region region) {
|
private void findNeededCuboidChunks(Region region) {
|
||||||
Vector min = region.getMinimumPoint();
|
Vector min = region.getMinimumPoint();
|
||||||
@ -97,14 +103,7 @@ public class SnapshotRestore {
|
|||||||
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
|
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
||||||
Vector pos = new Vector(x, y, z);
|
Vector pos = new Vector(x, y, z);
|
||||||
BlockVector2D chunkPos = ChunkStore.toChunk(pos);
|
checkAndAddBlock(pos);
|
||||||
|
|
||||||
// Unidentified chunk
|
|
||||||
if (!neededChunks.containsKey(chunkPos)) {
|
|
||||||
neededChunks.put(chunkPos, new ArrayList<Vector>());
|
|
||||||
}
|
|
||||||
|
|
||||||
neededChunks.get(chunkPos).add(pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,23 +112,30 @@ public class SnapshotRestore {
|
|||||||
/**
|
/**
|
||||||
* Find needed chunks in the region.
|
* Find needed chunks in the region.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region The {@link Region} to iterate
|
||||||
*/
|
*/
|
||||||
private void findNeededChunks(Region region) {
|
private void findNeededChunks(Region region) {
|
||||||
// First, we need to group points by chunk so that we only need
|
// First, we need to group points by chunk so that we only need
|
||||||
// to keep one chunk in memory at any given moment
|
// to keep one chunk in memory at any given moment
|
||||||
for (Vector pos : region) {
|
for (Vector pos : region) {
|
||||||
BlockVector2D chunkPos = ChunkStore.toChunk(pos);
|
checkAndAddBlock(pos);
|
||||||
|
|
||||||
// Unidentified chunk
|
|
||||||
if (!neededChunks.containsKey(chunkPos)) {
|
|
||||||
neededChunks.put(chunkPos, new ArrayList<Vector>());
|
|
||||||
}
|
|
||||||
|
|
||||||
neededChunks.get(chunkPos).add(pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAndAddBlock(Vector pos) {
|
||||||
|
if (editSession.getMask() != null && !editSession.getMask().matches(editSession, pos))
|
||||||
|
return;
|
||||||
|
|
||||||
|
BlockVector2D chunkPos = ChunkStore.toChunk(pos);
|
||||||
|
|
||||||
|
// Unidentified chunk
|
||||||
|
if (!neededChunks.containsKey(chunkPos)) {
|
||||||
|
neededChunks.put(chunkPos, new ArrayList<Vector>());
|
||||||
|
}
|
||||||
|
|
||||||
|
neededChunks.get(chunkPos).add(pos);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of chunks that are needed.
|
* Get the number of chunks that are needed.
|
||||||
*
|
*
|
||||||
@ -142,11 +148,9 @@ public class SnapshotRestore {
|
|||||||
/**
|
/**
|
||||||
* Restores to world.
|
* Restores to world.
|
||||||
*
|
*
|
||||||
* @param editSession
|
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public void restore(EditSession editSession)
|
public void restore() throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
|
||||||
|
|
||||||
missingChunks = new ArrayList<Vector2D>();
|
missingChunks = new ArrayList<Vector2D>();
|
||||||
errorChunks = new ArrayList<Vector2D>();
|
errorChunks = new ArrayList<Vector2D>();
|
||||||
|
Loading…
Reference in New Issue
Block a user