mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-17 06:03:53 +00:00
Merge remote-tracking branch 'remotes/pull_117/multiworld-snapshots'
This commit is contained in:
@ -50,7 +50,7 @@ public abstract class ChunkStore {
|
||||
* @throws DataException
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract CompoundTag getChunkTag(Vector2D pos)
|
||||
public abstract CompoundTag getChunkTag(Vector2D pos, String world)
|
||||
throws DataException, IOException;
|
||||
|
||||
/**
|
||||
@ -62,9 +62,9 @@ public abstract class ChunkStore {
|
||||
* @throws IOException
|
||||
* @throws DataException
|
||||
*/
|
||||
public Chunk getChunk(Vector2D pos)
|
||||
public Chunk getChunk(Vector2D pos, String world)
|
||||
throws DataException, IOException {
|
||||
return new Chunk(getChunkTag(pos));
|
||||
return new Chunk(getChunkTag(pos, world));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,13 +42,16 @@ public class FileMcRegionChunkStore extends McRegionChunkStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getInputStream(String name) throws IOException,
|
||||
protected InputStream getInputStream(String name, String world) 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public abstract class LegacyChunkStore extends ChunkStore {
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public CompoundTag getChunkTag(Vector2D pos)
|
||||
public CompoundTag getChunkTag(Vector2D pos, String world)
|
||||
throws DataException, IOException {
|
||||
int x = pos.getBlockX();
|
||||
int z = pos.getBlockZ();
|
||||
|
@ -46,7 +46,7 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
return filename;
|
||||
}
|
||||
|
||||
protected McRegionReader getReader(Vector2D pos) throws DataException, IOException {
|
||||
protected McRegionReader getReader(Vector2D pos, String worldname) throws DataException, IOException {
|
||||
String filename = getFilename(pos);
|
||||
if (curFilename != null) {
|
||||
if (curFilename.equals(filename)) {
|
||||
@ -58,17 +58,17 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
}
|
||||
}
|
||||
}
|
||||
InputStream stream = getInputStream(filename);
|
||||
InputStream stream = getInputStream(filename, worldname);
|
||||
cachedReader = new McRegionReader(stream);
|
||||
//curFilename = filename;
|
||||
return cachedReader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getChunkTag(Vector2D pos) throws DataException,
|
||||
public CompoundTag getChunkTag(Vector2D pos, String worldname) throws DataException,
|
||||
IOException {
|
||||
|
||||
McRegionReader reader = getReader(pos);
|
||||
McRegionReader reader = getReader(pos, worldname);
|
||||
InputStream stream = reader.getChunkInputStream(pos);
|
||||
NBTInputStream nbt = new NBTInputStream(stream);
|
||||
Tag tag;
|
||||
@ -113,7 +113,7 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
protected abstract InputStream getInputStream(String name)
|
||||
protected abstract InputStream getInputStream(String name, String worldname)
|
||||
throws IOException, DataException;
|
||||
|
||||
|
||||
|
@ -0,0 +1,54 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class MissingWorldException extends ChunkStoreException {
|
||||
|
||||
private static final long serialVersionUID = 6487395784195658467L;
|
||||
|
||||
private String worldname;
|
||||
|
||||
public MissingWorldException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MissingWorldException(String worldname) {
|
||||
super();
|
||||
this.worldname = worldname;
|
||||
}
|
||||
|
||||
public MissingWorldException(String msg, String worldname) {
|
||||
super(msg);
|
||||
this.worldname = worldname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of the world in question. May be null if unknown.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getWorldname() {
|
||||
return worldname;
|
||||
}
|
||||
}
|
@ -15,8 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
*/
|
||||
package com.sk89q.worldedit.data;
|
||||
|
||||
import java.io.*;
|
||||
@ -32,6 +31,7 @@ import de.schlichtherle.util.zip.*;
|
||||
* @author sk89q
|
||||
*/
|
||||
public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||
|
||||
/**
|
||||
* ZIP file.
|
||||
*/
|
||||
@ -59,7 +59,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||
throws IOException, ZipException {
|
||||
this.zipFile = zipFile;
|
||||
this.folder = folder;
|
||||
|
||||
|
||||
zip = new ZipFile(zipFile);
|
||||
}
|
||||
|
||||
@ -88,57 +88,49 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected InputStream getInputStream(String name)
|
||||
protected InputStream getInputStream(String name, String worldname)
|
||||
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(".*[\\\\/]level\\.dat$");
|
||||
|
||||
// So not there either...
|
||||
if (testEntry == null) {
|
||||
for (Enumeration<? extends ZipEntry> 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;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(".*\\.mcr$");
|
||||
// World pattern
|
||||
Pattern worldPattern = Pattern.compile(worldname + "\\$");
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements();) {
|
||||
ZipEntry testEntry = (ZipEntry) e.nextElement();
|
||||
// Check for world
|
||||
if (worldPattern.matcher(worldname).matches()) {
|
||||
// Check for file
|
||||
if (pattern.matcher(testEntry.getName()).matches()) {
|
||||
folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/"));
|
||||
name = folder + "/" + name;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
file = "world/" + file;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if world is found
|
||||
if (folder == null) {
|
||||
throw new MissingWorldException("Target world is not present in ZIP.", worldname);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an entry from the ZIP, trying both types of slashes.
|
||||
*
|
||||
@ -167,15 +159,15 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isValid() {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements(); ) {
|
||||
|
||||
e.hasMoreElements();) {
|
||||
|
||||
ZipEntry testEntry = e.nextElement();
|
||||
|
||||
|
||||
if (testEntry.getName().matches(".*\\.mcr$")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
*/
|
||||
package com.sk89q.worldedit.data;
|
||||
|
||||
import java.io.*;
|
||||
@ -30,6 +29,7 @@ import java.util.Enumeration;
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
|
||||
/**
|
||||
* ZIP file.
|
||||
*/
|
||||
@ -57,7 +57,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
throws IOException, ZipException {
|
||||
this.zipFile = zipFile;
|
||||
this.folder = folder;
|
||||
|
||||
|
||||
zip = new ZipFile(zipFile);
|
||||
}
|
||||
|
||||
@ -85,57 +85,47 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
* @throws DataException
|
||||
*/
|
||||
@Override
|
||||
protected InputStream getInputStream(String name)
|
||||
protected InputStream getInputStream(String name, String worldname)
|
||||
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(".*[\\\\/]level\\.dat$");
|
||||
|
||||
// So not there either...
|
||||
if (testEntry == null) {
|
||||
for (Enumeration<? extends ZipEntry> 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;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(".*\\.mcr$");
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements();) {
|
||||
ZipEntry testEntry = (ZipEntry) e.nextElement();
|
||||
// Check for world
|
||||
if (testEntry.getName().startsWith(worldname + "/")) {
|
||||
if (pattern.matcher(testEntry.getName()).matches()) {
|
||||
folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/"));
|
||||
name = folder + "/" + name;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
file = "world/" + file;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Check if world is found
|
||||
if (folder == null) {
|
||||
throw new MissingWorldException("Target world is not present in ZIP.", worldname);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an entry from the ZIP, trying both types of slashes.
|
||||
*
|
||||
@ -163,15 +153,15 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements(); ) {
|
||||
|
||||
e.hasMoreElements();) {
|
||||
|
||||
ZipEntry testEntry = e.nextElement();
|
||||
|
||||
|
||||
if (testEntry.getName().matches(".*\\.mcr$")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user