From 73a86468feb60e1668a83e3916737a981d8d11e0 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Thu, 7 Jul 2011 19:10:36 +0100 Subject: [PATCH] Add nether snapshot support --- .../data/FileMcRegionChunkStore.java | 12 ++++-- .../data/TrueZipMcRegionChunkStore.java | 40 +++++-------------- .../data/ZippedMcRegionChunkStore.java | 40 +++++-------------- 3 files changed, 30 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java index f6c2ce33f..291d1a000 100644 --- a/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java @@ -44,11 +44,14 @@ public class FileMcRegionChunkStore extends McRegionChunkStore { @Override protected InputStream getInputStream(String name) throws IOException, DataException { - - String file = "region" + File.separator + name; + String fileName = "region" + File.separator + name; + File file = new File(path, fileName); + if (!file.exists()) { + file = new File(path, "DIM-1" + File.separator + fileName); + } try { - return new FileInputStream(new File(path, file)); + return new FileInputStream(file); } catch (FileNotFoundException e) { throw new MissingChunkException(); } @@ -56,7 +59,8 @@ public class FileMcRegionChunkStore extends McRegionChunkStore { @Override public boolean isValid() { - return new File(path, "region").isDirectory(); + return new File(path, "region").isDirectory() || + new File(path, "DIM-1" + File.separator + "region").isDirectory(); } } diff --git a/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java index b066d73d2..763caf246 100644 --- a/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java @@ -90,52 +90,34 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore { @SuppressWarnings("unchecked") protected InputStream getInputStream(String name) throws IOException, DataException { - String file = "region/" + name; // Detect subfolder for the world's files if (folder != null) { if (!folder.equals("")) { - file = folder + "/" + file; + name = folder + "/" + name; } } else { - ZipEntry testEntry = zip.getEntry("level.dat"); - - // So, the data is not in the root directory - if (testEntry == null) { - // Let's try a world/ sub-directory - testEntry = getEntry("world/level.dat"); + Pattern pattern = Pattern.compile(".*\\.mcr$"); + for (Enumeration e = zip.entries(); + e.hasMoreElements(); ) { + ZipEntry testEntry = (ZipEntry)e.nextElement(); - Pattern pattern = Pattern.compile(".*[\\\\/]level\\.dat$"); - - // So not there either... - if (testEntry == null) { - for (Enumeration e = zip.entries(); - e.hasMoreElements(); ) { - - testEntry = e.nextElement(); - - // Whoo, found level.dat! - if (pattern.matcher(testEntry.getName()).matches()) { - folder = testEntry.getName().replaceAll("level\\.dat$", ""); - folder = folder.substring(0, folder.length() - 1); - file = folder + file; - break; - } - } - } else { - file = "world/" + file; + if (pattern.matcher(testEntry.getName()).matches()) { + folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/")); + name = folder + "/" + name; + break; } } } - ZipEntry entry = getEntry(file); + ZipEntry entry = getEntry(name); if (entry == null) { throw new MissingChunkException(); } try { return zip.getInputStream(entry); } catch (ZipException e) { - throw new IOException("Failed to read " + file + " in ZIP"); + throw new IOException("Failed to read " + name + " in ZIP"); } } diff --git a/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java index 124b43c02..10365d514 100644 --- a/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java @@ -87,52 +87,34 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { @Override protected InputStream getInputStream(String name) throws IOException, DataException { - String file = "region/" + name; // Detect subfolder for the world's files if (folder != null) { if (!folder.equals("")) { - file = folder + "/" + file; + name = folder + "/" + name; } } else { - ZipEntry testEntry = zip.getEntry("level.dat"); - - // So, the data is not in the root directory - if (testEntry == null) { - // Let's try a world/ sub-directory - testEntry = getEntry("world/level.dat"); + Pattern pattern = Pattern.compile(".*\\.mcr$"); + for (Enumeration e = zip.entries(); + e.hasMoreElements(); ) { + ZipEntry testEntry = (ZipEntry)e.nextElement(); - Pattern pattern = Pattern.compile(".*[\\\\/]level\\.dat$"); - - // So not there either... - if (testEntry == null) { - for (Enumeration e = zip.entries(); - e.hasMoreElements(); ) { - - testEntry = (ZipEntry)e.nextElement(); - - // Whoo, found level.dat! - if (pattern.matcher(testEntry.getName()).matches()) { - folder = testEntry.getName().replaceAll("level\\.dat$", ""); - folder = folder.substring(0, folder.length() - 1); - file = folder + file; - break; - } - } - } else { - file = "world/" + file; + if (pattern.matcher(testEntry.getName()).matches()) { + folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/")); + name = folder + "/" + name; + break; } } } - ZipEntry entry = getEntry(file); + ZipEntry entry = getEntry(name); if (entry == null) { throw new MissingChunkException(); } try { return zip.getInputStream(entry); } catch (ZipException e) { - throw new IOException("Failed to read " + file + " in ZIP"); + throw new IOException("Failed to read " + name + " in ZIP"); } }