mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-19 06:53:54 +00:00
Merge remote-tracking branch 'remotes/pull_117/multiworld-snapshots'
This commit is contained in:
@ -15,22 +15,22 @@
|
||||
*
|
||||
* 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.snapshots;
|
||||
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.io.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Snapshot implements Comparable<Snapshot> {
|
||||
|
||||
protected static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
/**
|
||||
* Stores snapshot file.
|
||||
*/
|
||||
@ -64,10 +64,10 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
*/
|
||||
public ChunkStore getChunkStore() throws IOException, DataException {
|
||||
ChunkStore chunkStore = _getChunkStore();
|
||||
|
||||
|
||||
logger.info("WorldEdit: Using " + chunkStore.getClass().getCanonicalName()
|
||||
+ " for loading snapshot '" + file.getAbsolutePath() + "'");
|
||||
|
||||
|
||||
return chunkStore;
|
||||
}
|
||||
|
||||
@ -82,19 +82,19 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
if (file.getName().toLowerCase().endsWith(".zip")) {
|
||||
try {
|
||||
ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file);
|
||||
|
||||
|
||||
if (!chunkStore.isValid()) {
|
||||
return new TrueZipLegacyChunkStore(file);
|
||||
}
|
||||
|
||||
|
||||
return chunkStore;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
ChunkStore chunkStore = new ZippedMcRegionChunkStore(file);
|
||||
|
||||
|
||||
if (!chunkStore.isValid()) {
|
||||
return new ZippedLegacyChunkStore(file);
|
||||
}
|
||||
|
||||
|
||||
return chunkStore;
|
||||
}
|
||||
} else if (file.getName().toLowerCase().endsWith(".tar.bz2")
|
||||
@ -102,26 +102,60 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
|| file.getName().toLowerCase().endsWith(".tar")) {
|
||||
try {
|
||||
ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file);
|
||||
|
||||
|
||||
if (!chunkStore.isValid()) {
|
||||
return new TrueZipLegacyChunkStore(file);
|
||||
}
|
||||
|
||||
|
||||
return chunkStore;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DataException("TrueZIP is required for .tar support");
|
||||
}
|
||||
} else {
|
||||
ChunkStore chunkStore = new FileMcRegionChunkStore(file);
|
||||
|
||||
|
||||
if (!chunkStore.isValid()) {
|
||||
return new FileLegacyChunkStore(file);
|
||||
}
|
||||
|
||||
|
||||
return chunkStore;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the zip/tar file it contains the given world.
|
||||
*
|
||||
* @return true if the zip/tar file contains the given world
|
||||
*/
|
||||
public boolean containsWorld(String worldname) {
|
||||
try {
|
||||
if (file.getName().toLowerCase().endsWith(".zip")) {
|
||||
ZipFile entry = new ZipFile(file);
|
||||
return entry.getEntry(worldname) != null;
|
||||
} else if (file.getName().toLowerCase().endsWith(".tar.bz2")
|
||||
|| file.getName().toLowerCase().endsWith(".tar.gz")
|
||||
|| file.getName().toLowerCase().endsWith(".tar")) {
|
||||
try {
|
||||
de.schlichtherle.util.zip.ZipFile entry = new de.schlichtherle.util.zip.ZipFile(file);
|
||||
|
||||
return entry.getEntry(worldname) != null;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new DataException("TrueZIP is required for .tar support");
|
||||
}
|
||||
} else {
|
||||
return (file.getName().equalsIgnoreCase(worldname));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// Skip the file, but print an error
|
||||
logger.info("Could not load snapshot: "
|
||||
+ file.getPath());
|
||||
} catch (DataException ex) {
|
||||
// No truezip, so tar file not supported.
|
||||
// Dont print, just skip the file.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the snapshot's name.
|
||||
*
|
||||
@ -130,7 +164,7 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the file for the snapshot.
|
||||
*
|
||||
@ -139,7 +173,7 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the date associated with this snapshot.
|
||||
*
|
||||
@ -148,7 +182,7 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
public Calendar getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the date of the snapshot.
|
||||
*
|
||||
@ -160,12 +194,14 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||
|
||||
public int compareTo(Snapshot o) {
|
||||
if (o.date == null || date == null) {
|
||||
return name.compareTo(o.name);
|
||||
// Remove the folder from the name
|
||||
int i = name.indexOf("/"), j = o.name.indexOf("/");
|
||||
return name.substring((i > 0 ? 0 : i)).compareTo(o.name.substring((j > 0 ? 0 : j)));
|
||||
} else {
|
||||
return date.compareTo(o.date);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Snapshot) {
|
||||
|
@ -15,10 +15,10 @@
|
||||
*
|
||||
* 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.snapshots;
|
||||
|
||||
import com.sk89q.worldedit.data.MissingWorldException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@ -30,16 +30,15 @@ import java.util.List;
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SnapshotRepository {
|
||||
|
||||
/**
|
||||
* Stores the directory the snapshots come from.
|
||||
*/
|
||||
protected File dir;
|
||||
|
||||
/**
|
||||
* List of date parsers.
|
||||
*/
|
||||
protected List<SnapshotDateParser> dateParsers
|
||||
= new ArrayList<SnapshotDateParser>();
|
||||
protected List<SnapshotDateParser> dateParsers = new ArrayList<SnapshotDateParser>();
|
||||
|
||||
/**
|
||||
* Create a new instance of a repository.
|
||||
@ -48,6 +47,8 @@ public class SnapshotRepository {
|
||||
*/
|
||||
public SnapshotRepository(File dir) {
|
||||
this.dir = dir;
|
||||
// If folder dont exist, make it.
|
||||
dir.mkdirs();
|
||||
|
||||
dateParsers.add(new YYMMDDHHIISSParser());
|
||||
dateParsers.add(new ModificationTimerParser());
|
||||
@ -69,7 +70,7 @@ public class SnapshotRepository {
|
||||
* @param newestFirst
|
||||
* @return
|
||||
*/
|
||||
public List<Snapshot> getSnapshots(boolean newestFirst) {
|
||||
public List<Snapshot> getSnapshots(boolean newestFirst, String worldname) throws MissingWorldException {
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
File f = new File(dir, name);
|
||||
@ -77,13 +78,23 @@ public class SnapshotRepository {
|
||||
}
|
||||
};
|
||||
|
||||
String[] snapshotNames = dir.list(filter);
|
||||
List<Snapshot> list = new ArrayList<Snapshot>(snapshotNames.length);
|
||||
|
||||
for (String name : snapshotNames) {
|
||||
Snapshot snapshot = new Snapshot(this, name);
|
||||
detectDate(snapshot);
|
||||
list.add(snapshot);
|
||||
File[] snapshotFiles = dir.listFiles();
|
||||
List<Snapshot> list = new ArrayList<Snapshot>(snapshotFiles.length);
|
||||
|
||||
for (File file : snapshotFiles) {
|
||||
if (isValidSnapshot(file)) {
|
||||
Snapshot snapshot = new Snapshot(this, file.getName());
|
||||
if (snapshot.containsWorld(worldname)) {
|
||||
detectDate(snapshot);
|
||||
list.add(snapshot);
|
||||
}
|
||||
} else if (file.isDirectory() && file.getName().equalsIgnoreCase(worldname)) {
|
||||
for (String name : file.list(filter)) {
|
||||
Snapshot snapshot = new Snapshot(this, file.getName() + "/" + name);
|
||||
detectDate(snapshot);
|
||||
list.add(snapshot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newestFirst) {
|
||||
@ -94,50 +105,50 @@ public class SnapshotRepository {
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first snapshot after a date.
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public Snapshot getSnapshotAfter(Calendar date) {
|
||||
List<Snapshot> snapshots = getSnapshots(true);
|
||||
public Snapshot getSnapshotAfter(Calendar date, String world) throws MissingWorldException {
|
||||
List<Snapshot> snapshots = getSnapshots(true, world);
|
||||
Snapshot last = null;
|
||||
|
||||
|
||||
for (Snapshot snapshot : snapshots) {
|
||||
if (snapshot.getDate() != null
|
||||
&& snapshot.getDate().before(date)) {
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
last = snapshot;
|
||||
}
|
||||
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first snapshot before a date.
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public Snapshot getSnapshotBefore(Calendar date) {
|
||||
List<Snapshot> snapshots = getSnapshots(false);
|
||||
public Snapshot getSnapshotBefore(Calendar date, String world) throws MissingWorldException {
|
||||
List<Snapshot> snapshots = getSnapshots(false, world);
|
||||
Snapshot last = null;
|
||||
|
||||
|
||||
for (Snapshot snapshot : snapshots) {
|
||||
if (snapshot.getDate().after(date)) {
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
last = snapshot;
|
||||
}
|
||||
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to detect a snapshot's date and assign it.
|
||||
*
|
||||
@ -151,7 +162,7 @@ public class SnapshotRepository {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
snapshot.setDate(null);
|
||||
}
|
||||
|
||||
@ -160,8 +171,8 @@ public class SnapshotRepository {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Snapshot getDefaultSnapshot() {
|
||||
List<Snapshot> snapshots = getSnapshots(true);
|
||||
public Snapshot getDefaultSnapshot(String world) throws MissingWorldException {
|
||||
List<Snapshot> snapshots = getSnapshots(true, world);
|
||||
|
||||
if (snapshots.size() == 0) {
|
||||
return null;
|
||||
@ -186,18 +197,16 @@ public class SnapshotRepository {
|
||||
* @param f
|
||||
* @return whether it is a valid snapshot
|
||||
*/
|
||||
public boolean isValidSnapshot(File f) {
|
||||
protected boolean isValidSnapshot(File f) {
|
||||
if (!f.getName().matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (f.isDirectory() && (new File(f, "level.dat")).exists())
|
||||
|| (f.isFile() && (
|
||||
f.getName().toLowerCase().endsWith(".zip")
|
||||
|| f.getName().toLowerCase().endsWith(".tar.bz2")
|
||||
|| f.getName().toLowerCase().endsWith(".tar.gz")
|
||||
|| f.getName().toLowerCase().endsWith(".tar")
|
||||
));
|
||||
|| (f.isFile() && (f.getName().toLowerCase().endsWith(".zip")
|
||||
|| f.getName().toLowerCase().endsWith(".tar.bz2")
|
||||
|| f.getName().toLowerCase().endsWith(".tar.gz")
|
||||
|| f.getName().toLowerCase().endsWith(".tar")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +147,7 @@ public class SnapshotRestore {
|
||||
Chunk chunk;
|
||||
|
||||
try {
|
||||
chunk = chunkStore.getChunk(chunkPos);
|
||||
chunk = chunkStore.getChunk(chunkPos, editSession.getWorld().getName());
|
||||
// Good, the chunk could be at least loaded
|
||||
|
||||
// Now just copy blocks!
|
||||
@ -157,6 +157,9 @@ public class SnapshotRestore {
|
||||
}
|
||||
} catch (MissingChunkException me) {
|
||||
missingChunks.add(chunkPos);
|
||||
} catch (MissingWorldException me) {
|
||||
errorChunks.add(chunkPos);
|
||||
lastErrorMessage = me.getMessage();
|
||||
} catch (DataException de) {
|
||||
errorChunks.add(chunkPos);
|
||||
lastErrorMessage = de.getMessage();
|
||||
|
Reference in New Issue
Block a user