From 97380f28debb4bd9de6b5ecf2aafc3e23dcf2d2e Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 9 Jul 2012 23:55:19 -0700 Subject: [PATCH] Fixed snapshots not properly loading .mcr files, made snapshots use fast mode. --- .../com/sk89q/worldedit/data/McRegionChunkStore.java | 2 +- .../worldedit/data/TrueZipMcRegionChunkStore.java | 10 +--------- .../worldedit/data/ZippedMcRegionChunkStore.java | 11 ++--------- .../sk89q/worldedit/snapshots/SnapshotRestore.java | 7 ++++++- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java index a958d1cb2..8bbb75b0a 100644 --- a/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java @@ -42,7 +42,7 @@ public abstract class McRegionChunkStore extends ChunkStore { int x = pos.getBlockX(); int z = pos.getBlockZ(); - String filename = "r." + (x >> 5) + "." + (z >> 5) + ".mcr"; + String filename = "r." + (x >> 5) + "." + (z >> 5) + ".mca"; return filename; } diff --git a/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java index 29c14774d..201cfd053 100644 --- a/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java @@ -100,21 +100,13 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore { name = folder + "/" + name; } } else { - Pattern pattern = Pattern.compile(".*\\.mcr$"); - Pattern patternmca = Pattern.compile(".*\\.mca$"); // TODO: does this need a separate class? + Pattern pattern = Pattern.compile(".*\\.mc[ra]$"); // World pattern Pattern worldPattern = Pattern.compile(worldname + "\\$"); for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = (ZipEntry) e.nextElement(); // Check for world if (worldPattern.matcher(worldname).matches()) { - // Check for file - // TODO: does this need a separate class? - if (patternmca.matcher(testEntry.getName()).matches()) { - folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/")); - name = folder + "/" + name.replace("mcr", "mca"); - break; - } // Check for file if (pattern.matcher(testEntry.getName()).matches()) { folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/")); diff --git a/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java index f7f85a2ff..5c1e64d81 100644 --- a/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java @@ -98,19 +98,12 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { name = folder + "/" + name; } } else { - Pattern pattern = Pattern.compile(".*\\.mcr$"); - Pattern patternmca = Pattern.compile(".*\\.mca$"); // TODO: does this need a separate class? + Pattern pattern = Pattern.compile(".*\\.mc[ra]$"); for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = (ZipEntry) e.nextElement(); // Check for world if (testEntry.getName().startsWith(worldname + "/")) { - // TODO: does this need a separate class? - if (patternmca.matcher(testEntry.getName()).matches()) { - folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/")); - name = folder + "/" + name.replace("mcr", "mca"); - break; - } - if (pattern.matcher(testEntry.getName()).matches()) { + if (pattern.matcher(testEntry.getName()).matches()) { // does entry end in .mca folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/")); name = folder + "/" + name; break; diff --git a/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java b/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java index bcdd293e1..c66f23d1e 100644 --- a/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java +++ b/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java @@ -155,6 +155,9 @@ public class SnapshotRestore { for (Map.Entry> entry : neededChunks.entrySet()) { BlockVector2D chunkPos = entry.getKey(); Chunk chunk; + + boolean hasFastMode = editSession.hasFastMode(); + editSession.setFastMode(true); try { chunk = chunkStore.getChunk(chunkPos, editSession.getWorld()); @@ -163,7 +166,7 @@ public class SnapshotRestore { // Now just copy blocks! for (Vector pos : entry.getValue()) { BaseBlock block = chunk.getBlock(pos); - editSession.setBlock(pos, block); + editSession.rawSetBlock(pos, block); } } catch (MissingChunkException me) { missingChunks.add(chunkPos); @@ -176,6 +179,8 @@ public class SnapshotRestore { } catch (IOException ioe) { errorChunks.add(chunkPos); lastErrorMessage = ioe.getMessage(); + } finally { + editSession.setFastMode(hasFastMode); } } }