From 351fd6771ac3459bfd3d5eef1bb1a00391fab87f Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 6 Jun 2019 10:34:12 -0400 Subject: [PATCH] Restore ability to restore old MCRegion files. --- .../com/sk89q/worldedit/world/storage/ChunkStore.java | 2 +- .../worldedit/world/storage/McRegionChunkStore.java | 2 +- .../world/storage/TrueZipMcRegionChunkStore.java | 11 +++++++++-- .../world/storage/ZippedMcRegionChunkStore.java | 11 +++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java index edd0799b4..1b89c8b09 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java @@ -109,7 +109,7 @@ public abstract class ChunkStore implements Closeable { if (dataVersion == 0) dataVersion = -1; final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING); final int currentDataVersion = platform.getDataVersion(); - if (dataVersion < currentDataVersion) { + if (tag.getValue().containsKey("Sections") && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks final DataFixer dataFixer = platform.getDataFixer(); if (dataFixer != null) { return new AnvilChunk13((CompoundTag) dataFixer.fixUp(DataFixer.FixTypes.CHUNK, rootTag, dataVersion).getValue().get("Level")); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java index 5c4eabfd9..a80a05e2f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java @@ -78,7 +78,7 @@ public abstract class McRegionChunkStore extends ChunkStore { throw new ChunkStoreException("CompoundTag expected for chunk; got " + tag.getClass().getName()); } - return (CompoundTag)tag; + return (CompoundTag) tag; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java index 8d7c03e93..80e2f814d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java @@ -115,7 +115,14 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore { ZipEntry entry = getEntry(name); if (entry == null) { - throw new MissingChunkException(); + if (name.endsWith(".mca")) { // try old mcr format + entry = getEntry(name.replace(".mca", ".mcr")); + if (entry == null) { + throw new MissingChunkException(); + } + } else { + throw new MissingChunkException(); + } } try { return zip.getInputStream(entry); @@ -150,7 +157,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore { ZipEntry testEntry = e.nextElement(); - if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { // TODO: does this need a separate class? + if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { return true; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java index 581686ea4..afb9cff72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java @@ -102,7 +102,14 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { ZipEntry entry = getEntry(name); if (entry == null) { - throw new MissingChunkException(); + if (name.endsWith(".mca")) { // try old mcr format + entry = getEntry(name.replace(".mca", ".mcr")); + if (entry == null) { + throw new MissingChunkException(); + } + } else { + throw new MissingChunkException(); + } } try { return zip.getInputStream(entry); @@ -136,7 +143,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { ZipEntry testEntry = e.nextElement(); - if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { // TODO: does this need a separate class? + if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { return true; } }