mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 10:17:39 +00:00
Merge remote-tracking branch 'remotes/pull_117/multiworld-snapshots'
This commit is contained in:
commit
990915b23f
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents WorldEdit's configuration.
|
* Represents WorldEdit's configuration.
|
||||||
|
@ -35,6 +35,13 @@ public abstract class LocalWorld {
|
|||||||
*/
|
*/
|
||||||
protected Random random = new Random();
|
protected Random random = new Random();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the world.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set block type.
|
* Set block type.
|
||||||
*
|
*
|
||||||
|
@ -86,10 +86,8 @@ public class BukkitConfiguration extends LocalConfiguration {
|
|||||||
LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
|
LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
|
||||||
|
|
||||||
String snapshotsDir = config.getString("snapshots.directory", "");
|
String snapshotsDir = config.getString("snapshots.directory", "");
|
||||||
if (!snapshotsDir.trim().equals("")) {
|
if (!snapshotsDir.isEmpty()){
|
||||||
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
||||||
} else {
|
|
||||||
snapshotRepo = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String type = config.getString("shell-save-type", "").trim();
|
String type = config.getString("shell-save-type", "").trim();
|
||||||
|
@ -70,6 +70,15 @@ public class BukkitWorld extends LocalWorld {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the world
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return world.getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set block type.
|
* Set block type.
|
||||||
*
|
*
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.commands;
|
package com.sk89q.worldedit.commands;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -30,6 +29,7 @@ import com.sk89q.minecraft.util.commands.Command;
|
|||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
import com.sk89q.worldedit.data.MissingWorldException;
|
||||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||||
|
|
||||||
@ -39,16 +39,15 @@ import com.sk89q.worldedit.snapshots.Snapshot;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class SnapshotCommands {
|
public class SnapshotCommands {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = {"list"},
|
||||||
aliases = {"list"},
|
|
||||||
usage = "[num]",
|
usage = "[num]",
|
||||||
desc = "List snapshots",
|
desc = "List snapshots",
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 1
|
max = 1)
|
||||||
)
|
|
||||||
@CommandPermissions({"worldedit.snapshots.list"})
|
@CommandPermissions({"worldedit.snapshots.list"})
|
||||||
public static void list(CommandContext args, WorldEdit we,
|
public static void list(CommandContext args, WorldEdit we,
|
||||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
@ -56,14 +55,20 @@ public class SnapshotCommands {
|
|||||||
|
|
||||||
LocalConfiguration config = we.getConfiguration();
|
LocalConfiguration config = we.getConfiguration();
|
||||||
|
|
||||||
int num = args.argsLength() > 0 ?
|
if (config.snapshotRepo == null) {
|
||||||
Math.min(40, Math.max(5, args.getInteger(0))) : 5;
|
player.printError("Snapshot/backup restore is not configured.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (config.snapshotRepo != null) {
|
try {
|
||||||
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true);
|
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, player.getWorld().getName());
|
||||||
|
|
||||||
if (snapshots.size() > 0) {
|
if (snapshots.size() > 0) {
|
||||||
for (byte i = 0; i < Math.min(num, snapshots.size()); ++i) {
|
|
||||||
|
int num = args.argsLength() > 0 ? Math.min(40, Math.max(5, args.getInteger(0))) : 5;
|
||||||
|
|
||||||
|
player.print("Snapshots for world: '" + player.getWorld().getName() + "'");
|
||||||
|
for (byte i = 0; i < Math.min(num, snapshots.size()); i++) {
|
||||||
player.print((i + 1) + ". " + snapshots.get(i).getName());
|
player.print((i + 1) + ". " + snapshots.get(i).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,26 +80,24 @@ public class SnapshotCommands {
|
|||||||
File dir = config.snapshotRepo.getDirectory();
|
File dir = config.snapshotRepo.getDirectory();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
logger.info("WorldEdit found no snapshots: looked in: "
|
||||||
dir.getCanonicalPath());
|
+ dir.getCanonicalPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.info("WorldEdit found no snapshots: looked in "
|
logger.info("WorldEdit found no snapshots: looked in "
|
||||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
+ "(NON-RESOLVABLE PATH - does it exist?): "
|
||||||
dir.getPath());
|
+ dir.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} catch (MissingWorldException ex) {
|
||||||
player.printError("Snapshot/backup restore is not configured.");
|
player.printError("No snapshots were found for this world.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = {"use"},
|
||||||
aliases = {"use"},
|
|
||||||
usage = "<snapshot>",
|
usage = "<snapshot>",
|
||||||
desc = "Choose a snapshot to use",
|
desc = "Choose a snapshot to use",
|
||||||
min = 1,
|
min = 1,
|
||||||
max = 1
|
max = 1)
|
||||||
)
|
|
||||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||||
public static void use(CommandContext args, WorldEdit we,
|
public static void use(CommandContext args, WorldEdit we,
|
||||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
@ -111,7 +114,8 @@ public class SnapshotCommands {
|
|||||||
|
|
||||||
// Want the latest snapshot?
|
// Want the latest snapshot?
|
||||||
if (name.equalsIgnoreCase("latest")) {
|
if (name.equalsIgnoreCase("latest")) {
|
||||||
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot();
|
try {
|
||||||
|
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(player.getWorld().getName());
|
||||||
|
|
||||||
if (snapshot != null) {
|
if (snapshot != null) {
|
||||||
session.setSnapshot(null);
|
session.setSnapshot(null);
|
||||||
@ -119,6 +123,9 @@ public class SnapshotCommands {
|
|||||||
} else {
|
} else {
|
||||||
player.printError("No snapshots were found.");
|
player.printError("No snapshots were found.");
|
||||||
}
|
}
|
||||||
|
} catch (MissingWorldException ex) {
|
||||||
|
player.printError("No snapshots were found for this world.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
|
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
|
||||||
@ -129,13 +136,11 @@ public class SnapshotCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = {"before"},
|
||||||
aliases = {"before"},
|
|
||||||
usage = "<date>",
|
usage = "<date>",
|
||||||
desc = "Choose the nearest snapshot before a date",
|
desc = "Choose the nearest snapshot before a date",
|
||||||
min = 1,
|
min = 1,
|
||||||
max = -1
|
max = -1)
|
||||||
)
|
|
||||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||||
public static void before(CommandContext args, WorldEdit we,
|
public static void before(CommandContext args, WorldEdit we,
|
||||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
@ -153,26 +158,28 @@ public class SnapshotCommands {
|
|||||||
if (date == null) {
|
if (date == null) {
|
||||||
player.printError("Could not detect the date inputted.");
|
player.printError("Could not detect the date inputted.");
|
||||||
} else {
|
} else {
|
||||||
dateFormat.setTimeZone(session.getTimeZone());
|
try {
|
||||||
|
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date, player.getWorld().getName());
|
||||||
|
|
||||||
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date);
|
|
||||||
if (snapshot == null) {
|
if (snapshot == null) {
|
||||||
|
dateFormat.setTimeZone(session.getTimeZone());
|
||||||
player.printError("Couldn't find a snapshot before "
|
player.printError("Couldn't find a snapshot before "
|
||||||
+ dateFormat.format(date.getTime()) + ".");
|
+ dateFormat.format(date.getTime()) + ".");
|
||||||
} else {
|
} else {
|
||||||
session.setSnapshot(snapshot);
|
session.setSnapshot(snapshot);
|
||||||
player.print("Snapshot set to: " + snapshot.getName());
|
player.print("Snapshot set to: " + snapshot.getName());
|
||||||
}
|
}
|
||||||
|
} catch (MissingWorldException ex) {
|
||||||
|
player.printError("No snapshots were found for this world.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = {"after"},
|
||||||
aliases = {"after"},
|
|
||||||
usage = "<date>",
|
usage = "<date>",
|
||||||
desc = "Choose the nearest snapshot after a date",
|
desc = "Choose the nearest snapshot after a date",
|
||||||
min = 1,
|
min = 1,
|
||||||
max = -1
|
max = -1)
|
||||||
)
|
|
||||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||||
public static void after(CommandContext args, WorldEdit we,
|
public static void after(CommandContext args, WorldEdit we,
|
||||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
@ -190,16 +197,19 @@ public class SnapshotCommands {
|
|||||||
if (date == null) {
|
if (date == null) {
|
||||||
player.printError("Could not detect the date inputted.");
|
player.printError("Could not detect the date inputted.");
|
||||||
} else {
|
} else {
|
||||||
dateFormat.setTimeZone(session.getTimeZone());
|
try {
|
||||||
|
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, player.getWorld().getName());
|
||||||
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date);
|
|
||||||
if (snapshot == null) {
|
if (snapshot == null) {
|
||||||
|
dateFormat.setTimeZone(session.getTimeZone());
|
||||||
player.printError("Couldn't find a snapshot after "
|
player.printError("Couldn't find a snapshot after "
|
||||||
+ dateFormat.format(date.getTime()) + ".");
|
+ dateFormat.format(date.getTime()) + ".");
|
||||||
} else {
|
} else {
|
||||||
session.setSnapshot(snapshot);
|
session.setSnapshot(snapshot);
|
||||||
player.print("Snapshot set to: " + snapshot.getName());
|
player.print("Snapshot set to: " + snapshot.getName());
|
||||||
}
|
}
|
||||||
|
} catch (MissingWorldException ex) {
|
||||||
|
player.printError("No snapshots were found for this world.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,31 +34,29 @@ import com.sk89q.worldedit.WorldEdit;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.data.ChunkStore;
|
import com.sk89q.worldedit.data.ChunkStore;
|
||||||
import com.sk89q.worldedit.data.DataException;
|
import com.sk89q.worldedit.data.DataException;
|
||||||
|
import com.sk89q.worldedit.data.MissingWorldException;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||||
import com.sk89q.worldedit.snapshots.SnapshotRestore;
|
import com.sk89q.worldedit.snapshots.SnapshotRestore;
|
||||||
|
|
||||||
public class SnapshotUtilCommands {
|
public class SnapshotUtilCommands {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = {"snapshot", "snap"},
|
||||||
aliases = {"snapshot", "snap"},
|
desc = "Snapshot commands")
|
||||||
desc = "Snapshot commands"
|
|
||||||
)
|
|
||||||
@NestedCommand({SnapshotCommands.class})
|
@NestedCommand({SnapshotCommands.class})
|
||||||
public static void snapshot(CommandContext args, WorldEdit we,
|
public static void snapshot(CommandContext args, WorldEdit we,
|
||||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
throws WorldEditException {
|
throws WorldEditException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = {"restore", "/restore"},
|
||||||
aliases = {"restore", "/restore"},
|
|
||||||
usage = "[snapshot]",
|
usage = "[snapshot]",
|
||||||
desc = "Restore the selection from a snapshot",
|
desc = "Restore the selection from a snapshot",
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 1
|
max = 1)
|
||||||
)
|
|
||||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||||
public static void restore(CommandContext args, WorldEdit we,
|
public static void restore(CommandContext args, WorldEdit we,
|
||||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
@ -85,11 +83,10 @@ public class SnapshotUtilCommands {
|
|||||||
snapshot = session.getSnapshot();
|
snapshot = session.getSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunkStore chunkStore = null;
|
|
||||||
|
|
||||||
// No snapshot set?
|
// No snapshot set?
|
||||||
if (snapshot == null) {
|
if (snapshot == null) {
|
||||||
snapshot = config.snapshotRepo.getDefaultSnapshot();
|
try {
|
||||||
|
snapshot = config.snapshotRepo.getDefaultSnapshot(player.getWorld().getName());
|
||||||
|
|
||||||
if (snapshot == null) {
|
if (snapshot == null) {
|
||||||
player.printError("No snapshots were found. See console for details.");
|
player.printError("No snapshots were found. See console for details.");
|
||||||
@ -98,17 +95,23 @@ public class SnapshotUtilCommands {
|
|||||||
File dir = config.snapshotRepo.getDirectory();
|
File dir = config.snapshotRepo.getDirectory();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
logger.info("WorldEdit found no snapshots: looked in: "
|
||||||
dir.getCanonicalPath());
|
+ dir.getCanonicalPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.info("WorldEdit found no snapshots: looked in "
|
logger.info("WorldEdit found no snapshots: looked in "
|
||||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
+ "(NON-RESOLVABLE PATH - does it exist?): "
|
||||||
dir.getPath());
|
+ dir.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (MissingWorldException ex) {
|
||||||
|
player.printError("No snapshots were found for this world.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ChunkStore chunkStore = null;
|
||||||
|
|
||||||
// Load chunk store
|
// Load chunk store
|
||||||
try {
|
try {
|
||||||
|
@ -50,7 +50,7 @@ public abstract class ChunkStore {
|
|||||||
* @throws DataException
|
* @throws DataException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public abstract CompoundTag getChunkTag(Vector2D pos)
|
public abstract CompoundTag getChunkTag(Vector2D pos, String world)
|
||||||
throws DataException, IOException;
|
throws DataException, IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,9 +62,9 @@ public abstract class ChunkStore {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws DataException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
public Chunk getChunk(Vector2D pos)
|
public Chunk getChunk(Vector2D pos, String world)
|
||||||
throws DataException, IOException {
|
throws DataException, IOException {
|
||||||
return new Chunk(getChunkTag(pos));
|
return new Chunk(getChunkTag(pos, world));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,13 +42,16 @@ public class FileMcRegionChunkStore extends McRegionChunkStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InputStream getInputStream(String name) throws IOException,
|
protected InputStream getInputStream(String name, String world) throws IOException,
|
||||||
DataException {
|
DataException {
|
||||||
|
String fileName = "region" + File.separator + name;
|
||||||
String file = "region" + File.separator + name;
|
File file = new File(path, fileName);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file = new File(path, "DIM-1" + File.separator + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new FileInputStream(new File(path, file));
|
return new FileInputStream(file);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new MissingChunkException();
|
throw new MissingChunkException();
|
||||||
}
|
}
|
||||||
@ -56,7 +59,8 @@ public class FileMcRegionChunkStore extends McRegionChunkStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid() {
|
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
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getChunkTag(Vector2D pos)
|
public CompoundTag getChunkTag(Vector2D pos, String world)
|
||||||
throws DataException, IOException {
|
throws DataException, IOException {
|
||||||
int x = pos.getBlockX();
|
int x = pos.getBlockX();
|
||||||
int z = pos.getBlockZ();
|
int z = pos.getBlockZ();
|
||||||
|
@ -46,7 +46,7 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected McRegionReader getReader(Vector2D pos) throws DataException, IOException {
|
protected McRegionReader getReader(Vector2D pos, String worldname) throws DataException, IOException {
|
||||||
String filename = getFilename(pos);
|
String filename = getFilename(pos);
|
||||||
if (curFilename != null) {
|
if (curFilename != null) {
|
||||||
if (curFilename.equals(filename)) {
|
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);
|
cachedReader = new McRegionReader(stream);
|
||||||
//curFilename = filename;
|
//curFilename = filename;
|
||||||
return cachedReader;
|
return cachedReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getChunkTag(Vector2D pos) throws DataException,
|
public CompoundTag getChunkTag(Vector2D pos, String worldname) throws DataException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
||||||
McRegionReader reader = getReader(pos);
|
McRegionReader reader = getReader(pos, worldname);
|
||||||
InputStream stream = reader.getChunkInputStream(pos);
|
InputStream stream = reader.getChunkInputStream(pos);
|
||||||
NBTInputStream nbt = new NBTInputStream(stream);
|
NBTInputStream nbt = new NBTInputStream(stream);
|
||||||
Tag tag;
|
Tag tag;
|
||||||
@ -113,7 +113,7 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
|||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected abstract InputStream getInputStream(String name)
|
protected abstract InputStream getInputStream(String name, String worldname)
|
||||||
throws IOException, DataException;
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,6 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.data;
|
package com.sk89q.worldedit.data;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -32,6 +31,7 @@ import de.schlichtherle.util.zip.*;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZIP file.
|
* ZIP file.
|
||||||
*/
|
*/
|
||||||
@ -88,54 +88,46 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected InputStream getInputStream(String name)
|
protected InputStream getInputStream(String name, String worldname)
|
||||||
throws IOException, DataException {
|
throws IOException, DataException {
|
||||||
String file = "region/" + name;
|
|
||||||
|
|
||||||
// Detect subfolder for the world's files
|
// Detect subfolder for the world's files
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
if (!folder.equals("")) {
|
if (!folder.equals("")) {
|
||||||
file = folder + "/" + file;
|
name = folder + "/" + name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ZipEntry testEntry = zip.getEntry("level.dat");
|
Pattern pattern = Pattern.compile(".*\\.mcr$");
|
||||||
|
// World pattern
|
||||||
// So, the data is not in the root directory
|
Pattern worldPattern = Pattern.compile(worldname + "\\$");
|
||||||
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();
|
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||||
e.hasMoreElements();) {
|
e.hasMoreElements();) {
|
||||||
|
ZipEntry testEntry = (ZipEntry) e.nextElement();
|
||||||
testEntry = e.nextElement();
|
// Check for world
|
||||||
|
if (worldPattern.matcher(worldname).matches()) {
|
||||||
// Whoo, found level.dat!
|
// Check for file
|
||||||
if (pattern.matcher(testEntry.getName()).matches()) {
|
if (pattern.matcher(testEntry.getName()).matches()) {
|
||||||
folder = testEntry.getName().replaceAll("level\\.dat$", "");
|
folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/"));
|
||||||
folder = folder.substring(0, folder.length() - 1);
|
name = folder + "/" + name;
|
||||||
file = folder + file;
|
|
||||||
break;
|
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) {
|
if (entry == null) {
|
||||||
throw new MissingChunkException();
|
throw new MissingChunkException();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return zip.getInputStream(entry);
|
return zip.getInputStream(entry);
|
||||||
} catch (ZipException e) {
|
} catch (ZipException e) {
|
||||||
throw new IOException("Failed to read " + file + " in ZIP");
|
throw new IOException("Failed to read " + name + " in ZIP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.data;
|
package com.sk89q.worldedit.data;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -30,6 +29,7 @@ import java.util.Enumeration;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZIP file.
|
* ZIP file.
|
||||||
*/
|
*/
|
||||||
@ -85,54 +85,44 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
|||||||
* @throws DataException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected InputStream getInputStream(String name)
|
protected InputStream getInputStream(String name, String worldname)
|
||||||
throws IOException, DataException {
|
throws IOException, DataException {
|
||||||
String file = "region/" + name;
|
|
||||||
|
|
||||||
// Detect subfolder for the world's files
|
// Detect subfolder for the world's files
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
if (!folder.equals("")) {
|
if (!folder.equals("")) {
|
||||||
file = folder + "/" + file;
|
name = folder + "/" + name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ZipEntry testEntry = zip.getEntry("level.dat");
|
Pattern pattern = Pattern.compile(".*\\.mcr$");
|
||||||
|
|
||||||
// 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();
|
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||||
e.hasMoreElements();) {
|
e.hasMoreElements();) {
|
||||||
|
ZipEntry testEntry = (ZipEntry) e.nextElement();
|
||||||
testEntry = (ZipEntry)e.nextElement();
|
// Check for world
|
||||||
|
if (testEntry.getName().startsWith(worldname + "/")) {
|
||||||
// Whoo, found level.dat!
|
|
||||||
if (pattern.matcher(testEntry.getName()).matches()) {
|
if (pattern.matcher(testEntry.getName()).matches()) {
|
||||||
folder = testEntry.getName().replaceAll("level\\.dat$", "");
|
folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/"));
|
||||||
folder = folder.substring(0, folder.length() - 1);
|
name = folder + "/" + name;
|
||||||
file = folder + file;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
file = "world/" + file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipEntry entry = getEntry(file);
|
// Check if world is found
|
||||||
|
if (folder == null) {
|
||||||
|
throw new MissingWorldException("Target world is not present in ZIP.", worldname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipEntry entry = getEntry(name);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
throw new MissingChunkException();
|
throw new MissingChunkException();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return zip.getInputStream(entry);
|
return zip.getInputStream(entry);
|
||||||
} catch (ZipException e) {
|
} catch (ZipException e) {
|
||||||
throw new IOException("Failed to read " + file + " in ZIP");
|
throw new IOException("Failed to read " + name + " in ZIP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.snapshots;
|
package com.sk89q.worldedit.snapshots;
|
||||||
|
|
||||||
import com.sk89q.worldedit.data.*;
|
import com.sk89q.worldedit.data.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class Snapshot implements Comparable<Snapshot> {
|
public class Snapshot implements Comparable<Snapshot> {
|
||||||
protected static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
|
||||||
|
|
||||||
|
protected static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
/**
|
/**
|
||||||
* Stores snapshot file.
|
* Stores snapshot file.
|
||||||
*/
|
*/
|
||||||
@ -122,6 +122,40 @@ public class Snapshot implements Comparable<Snapshot> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Get the snapshot's name.
|
||||||
*
|
*
|
||||||
@ -160,7 +194,9 @@ public class Snapshot implements Comparable<Snapshot> {
|
|||||||
|
|
||||||
public int compareTo(Snapshot o) {
|
public int compareTo(Snapshot o) {
|
||||||
if (o.date == null || date == null) {
|
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 {
|
} else {
|
||||||
return date.compareTo(o.date);
|
return date.compareTo(o.date);
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.snapshots;
|
package com.sk89q.worldedit.snapshots;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.data.MissingWorldException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -30,16 +30,15 @@ import java.util.List;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class SnapshotRepository {
|
public class SnapshotRepository {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the directory the snapshots come from.
|
* Stores the directory the snapshots come from.
|
||||||
*/
|
*/
|
||||||
protected File dir;
|
protected File dir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of date parsers.
|
* List of date parsers.
|
||||||
*/
|
*/
|
||||||
protected List<SnapshotDateParser> dateParsers
|
protected List<SnapshotDateParser> dateParsers = new ArrayList<SnapshotDateParser>();
|
||||||
= new ArrayList<SnapshotDateParser>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of a repository.
|
* Create a new instance of a repository.
|
||||||
@ -48,6 +47,8 @@ public class SnapshotRepository {
|
|||||||
*/
|
*/
|
||||||
public SnapshotRepository(File dir) {
|
public SnapshotRepository(File dir) {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
|
// If folder dont exist, make it.
|
||||||
|
dir.mkdirs();
|
||||||
|
|
||||||
dateParsers.add(new YYMMDDHHIISSParser());
|
dateParsers.add(new YYMMDDHHIISSParser());
|
||||||
dateParsers.add(new ModificationTimerParser());
|
dateParsers.add(new ModificationTimerParser());
|
||||||
@ -69,7 +70,7 @@ public class SnapshotRepository {
|
|||||||
* @param newestFirst
|
* @param newestFirst
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<Snapshot> getSnapshots(boolean newestFirst) {
|
public List<Snapshot> getSnapshots(boolean newestFirst, String worldname) throws MissingWorldException {
|
||||||
FilenameFilter filter = new FilenameFilter() {
|
FilenameFilter filter = new FilenameFilter() {
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
File f = new File(dir, name);
|
File f = new File(dir, name);
|
||||||
@ -77,14 +78,24 @@ public class SnapshotRepository {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
String[] snapshotNames = dir.list(filter);
|
File[] snapshotFiles = dir.listFiles();
|
||||||
List<Snapshot> list = new ArrayList<Snapshot>(snapshotNames.length);
|
List<Snapshot> list = new ArrayList<Snapshot>(snapshotFiles.length);
|
||||||
|
|
||||||
for (String name : snapshotNames) {
|
for (File file : snapshotFiles) {
|
||||||
Snapshot snapshot = new Snapshot(this, name);
|
if (isValidSnapshot(file)) {
|
||||||
|
Snapshot snapshot = new Snapshot(this, file.getName());
|
||||||
|
if (snapshot.containsWorld(worldname)) {
|
||||||
detectDate(snapshot);
|
detectDate(snapshot);
|
||||||
list.add(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) {
|
if (newestFirst) {
|
||||||
Collections.sort(list, Collections.reverseOrder());
|
Collections.sort(list, Collections.reverseOrder());
|
||||||
@ -101,8 +112,8 @@ public class SnapshotRepository {
|
|||||||
* @param date
|
* @param date
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Snapshot getSnapshotAfter(Calendar date) {
|
public Snapshot getSnapshotAfter(Calendar date, String world) throws MissingWorldException {
|
||||||
List<Snapshot> snapshots = getSnapshots(true);
|
List<Snapshot> snapshots = getSnapshots(true, world);
|
||||||
Snapshot last = null;
|
Snapshot last = null;
|
||||||
|
|
||||||
for (Snapshot snapshot : snapshots) {
|
for (Snapshot snapshot : snapshots) {
|
||||||
@ -123,8 +134,8 @@ public class SnapshotRepository {
|
|||||||
* @param date
|
* @param date
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Snapshot getSnapshotBefore(Calendar date) {
|
public Snapshot getSnapshotBefore(Calendar date, String world) throws MissingWorldException {
|
||||||
List<Snapshot> snapshots = getSnapshots(false);
|
List<Snapshot> snapshots = getSnapshots(false, world);
|
||||||
Snapshot last = null;
|
Snapshot last = null;
|
||||||
|
|
||||||
for (Snapshot snapshot : snapshots) {
|
for (Snapshot snapshot : snapshots) {
|
||||||
@ -160,8 +171,8 @@ public class SnapshotRepository {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Snapshot getDefaultSnapshot() {
|
public Snapshot getDefaultSnapshot(String world) throws MissingWorldException {
|
||||||
List<Snapshot> snapshots = getSnapshots(true);
|
List<Snapshot> snapshots = getSnapshots(true, world);
|
||||||
|
|
||||||
if (snapshots.size() == 0) {
|
if (snapshots.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -186,18 +197,16 @@ public class SnapshotRepository {
|
|||||||
* @param f
|
* @param f
|
||||||
* @return whether it is a valid snapshot
|
* @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_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
|
if (!f.getName().matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (f.isDirectory() && (new File(f, "level.dat")).exists())
|
return (f.isDirectory() && (new File(f, "level.dat")).exists())
|
||||||
|| (f.isFile() && (
|
|| (f.isFile() && (f.getName().toLowerCase().endsWith(".zip")
|
||||||
f.getName().toLowerCase().endsWith(".zip")
|
|
||||||
|| f.getName().toLowerCase().endsWith(".tar.bz2")
|
|| f.getName().toLowerCase().endsWith(".tar.bz2")
|
||||||
|| f.getName().toLowerCase().endsWith(".tar.gz")
|
|| f.getName().toLowerCase().endsWith(".tar.gz")
|
||||||
|| f.getName().toLowerCase().endsWith(".tar")
|
|| f.getName().toLowerCase().endsWith(".tar")));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +147,7 @@ public class SnapshotRestore {
|
|||||||
Chunk chunk;
|
Chunk chunk;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chunk = chunkStore.getChunk(chunkPos);
|
chunk = chunkStore.getChunk(chunkPos, editSession.getWorld().getName());
|
||||||
// Good, the chunk could be at least loaded
|
// Good, the chunk could be at least loaded
|
||||||
|
|
||||||
// Now just copy blocks!
|
// Now just copy blocks!
|
||||||
@ -157,6 +157,9 @@ public class SnapshotRestore {
|
|||||||
}
|
}
|
||||||
} catch (MissingChunkException me) {
|
} catch (MissingChunkException me) {
|
||||||
missingChunks.add(chunkPos);
|
missingChunks.add(chunkPos);
|
||||||
|
} catch (MissingWorldException me) {
|
||||||
|
errorChunks.add(chunkPos);
|
||||||
|
lastErrorMessage = me.getMessage();
|
||||||
} catch (DataException de) {
|
} catch (DataException de) {
|
||||||
errorChunks.add(chunkPos);
|
errorChunks.add(chunkPos);
|
||||||
lastErrorMessage = de.getMessage();
|
lastErrorMessage = de.getMessage();
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.util;
|
package com.sk89q.worldedit.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -35,6 +34,7 @@ import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class PropertiesConfiguration extends LocalConfiguration {
|
public class PropertiesConfiguration extends LocalConfiguration {
|
||||||
|
|
||||||
protected Properties properties;
|
protected Properties properties;
|
||||||
protected File path;
|
protected File path;
|
||||||
|
|
||||||
@ -93,10 +93,8 @@ public class PropertiesConfiguration extends LocalConfiguration {
|
|||||||
LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));
|
LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));
|
||||||
|
|
||||||
String snapshotsDir = getString("snapshots-dir", "");
|
String snapshotsDir = getString("snapshots-dir", "");
|
||||||
if (!snapshotsDir.trim().equals("")) {
|
if (!snapshotsDir.isEmpty()) {
|
||||||
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
||||||
} else {
|
|
||||||
snapshotRepo = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
@ -229,5 +227,4 @@ public class PropertiesConfiguration extends LocalConfiguration {
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user