From 1d68fdd11c9fea4fed4e6864a356c6d543ea0eed Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 9 Mar 2011 23:51:40 -0800 Subject: [PATCH] Added detection of McRegion-format worlds for snapshot detection. --- src/com/sk89q/worldedit/data/ChunkStore.java | 7 +++++++ src/com/sk89q/worldedit/data/FileLegacyChunkStore.java | 5 +++++ src/com/sk89q/worldedit/data/FileMcRegionChunkStore.java | 5 +++++ src/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java | 5 +++++ src/com/sk89q/worldedit/data/ZippedAlphaChunkStore.java | 5 +++++ src/com/sk89q/worldedit/snapshots/Snapshot.java | 8 +++++++- 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/com/sk89q/worldedit/data/ChunkStore.java b/src/com/sk89q/worldedit/data/ChunkStore.java index ef0432b3b..d7c956b72 100644 --- a/src/com/sk89q/worldedit/data/ChunkStore.java +++ b/src/com/sk89q/worldedit/data/ChunkStore.java @@ -75,4 +75,11 @@ public abstract class ChunkStore { public void close() throws IOException { } + + /** + * Returns whether the chunk store is of this type. + * + * @return + */ + public abstract boolean isValid(); } diff --git a/src/com/sk89q/worldedit/data/FileLegacyChunkStore.java b/src/com/sk89q/worldedit/data/FileLegacyChunkStore.java index 10c03c8f4..20f203049 100644 --- a/src/com/sk89q/worldedit/data/FileLegacyChunkStore.java +++ b/src/com/sk89q/worldedit/data/FileLegacyChunkStore.java @@ -62,4 +62,9 @@ public class FileLegacyChunkStore extends LegacyChunkStore { throw new MissingChunkException(); } } + + @Override + public boolean isValid() { + return true; // Yeah, oh well + } } diff --git a/src/com/sk89q/worldedit/data/FileMcRegionChunkStore.java b/src/com/sk89q/worldedit/data/FileMcRegionChunkStore.java index f9dabee69..f6c2ce33f 100644 --- a/src/com/sk89q/worldedit/data/FileMcRegionChunkStore.java +++ b/src/com/sk89q/worldedit/data/FileMcRegionChunkStore.java @@ -54,4 +54,9 @@ public class FileMcRegionChunkStore extends McRegionChunkStore { } } + @Override + public boolean isValid() { + return new File(path, "region").isDirectory(); + } + } diff --git a/src/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java b/src/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java index 736169fbe..287a4a3ce 100644 --- a/src/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java +++ b/src/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java @@ -164,4 +164,9 @@ public class TrueZipLegacyChunkStore extends LegacyChunkStore { public void close() throws IOException { zip.close(); } + + @Override + public boolean isValid() { + return true; // Yeah, oh well + } } diff --git a/src/com/sk89q/worldedit/data/ZippedAlphaChunkStore.java b/src/com/sk89q/worldedit/data/ZippedAlphaChunkStore.java index 8823d6117..80c4d0540 100644 --- a/src/com/sk89q/worldedit/data/ZippedAlphaChunkStore.java +++ b/src/com/sk89q/worldedit/data/ZippedAlphaChunkStore.java @@ -161,4 +161,9 @@ public class ZippedAlphaChunkStore extends LegacyChunkStore { public void close() throws IOException { zip.close(); } + + @Override + public boolean isValid() { + return true; // Yeah, oh well + } } diff --git a/src/com/sk89q/worldedit/snapshots/Snapshot.java b/src/com/sk89q/worldedit/snapshots/Snapshot.java index 356ff353b..8ac9199e3 100644 --- a/src/com/sk89q/worldedit/snapshots/Snapshot.java +++ b/src/com/sk89q/worldedit/snapshots/Snapshot.java @@ -73,7 +73,13 @@ public class Snapshot { throw new DataException("TrueZIP is required for .tar support"); } } else { - return new FileLegacyChunkStore(file); + ChunkStore chunkStore = new FileMcRegionChunkStore(file); + + if (!chunkStore.isValid()) { + return new FileLegacyChunkStore(file); + } + + return chunkStore; } }