mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Add multiworld snapshot support
This commit is contained in:
parent
1e9c5b2c76
commit
858f8d3c36
@ -24,6 +24,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents WorldEdit's configuration.
|
||||
@ -42,7 +43,7 @@ public abstract class LocalConfiguration {
|
||||
public int defaultChangeLimit = -1;
|
||||
public int maxChangeLimit = -1;
|
||||
public String shellSaveType = "";
|
||||
public SnapshotRepository snapshotRepo = null;
|
||||
public Map<String, SnapshotRepository> snapshotRepositories = null;
|
||||
public int maxRadius = -1;
|
||||
public int maxSuperPickaxeSize = 5;
|
||||
public int maxBrushRadius = 6;
|
||||
|
@ -70,7 +70,7 @@ public class LocalSession {
|
||||
= new HashMap<Integer, Tool>();
|
||||
private int maxBlocksChanged = -1;
|
||||
private boolean useInventory;
|
||||
private Snapshot snapshot;
|
||||
private Map<LocalWorld, Snapshot> snapshots = new HashMap();
|
||||
private String lastScript;
|
||||
private boolean beenToldVersion = false;
|
||||
private boolean hasCUISupport = false;
|
||||
@ -410,8 +410,8 @@ public class LocalSession {
|
||||
*
|
||||
* @return the snapshot
|
||||
*/
|
||||
public Snapshot getSnapshot() {
|
||||
return snapshot;
|
||||
public Snapshot getSnapshot(LocalWorld world) {
|
||||
return snapshots.get(world);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,8 +419,12 @@ public class LocalSession {
|
||||
*
|
||||
* @param snapshot
|
||||
*/
|
||||
public void setSnapshot(Snapshot snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
public void setSnapshot(LocalWorld world, Snapshot snapshot) {
|
||||
if (snapshot == null && snapshots.containsKey(world)) {
|
||||
snapshots.remove(world);
|
||||
} else {
|
||||
snapshots.put(world, snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,6 +34,13 @@ public abstract class LocalWorld {
|
||||
* Random generator.
|
||||
*/
|
||||
protected Random random = new Random();
|
||||
|
||||
/**
|
||||
* Get the name of the world.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Set block type.
|
||||
|
@ -30,6 +30,8 @@ import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LogFormat;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BukkitConfiguration extends LocalConfiguration {
|
||||
private Configuration config;
|
||||
@ -86,10 +88,11 @@ public class BukkitConfiguration extends LocalConfiguration {
|
||||
LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
|
||||
|
||||
String snapshotsDir = config.getString("snapshots.directory", "");
|
||||
snapshotRepositories = new HashMap();
|
||||
if (!snapshotsDir.trim().equals("")) {
|
||||
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
||||
} else {
|
||||
snapshotRepo = null;
|
||||
for (File repository : new File(snapshotsDir).listFiles()) {
|
||||
snapshotRepositories.put(repository.getName(), new SnapshotRepository(repository));
|
||||
}
|
||||
}
|
||||
|
||||
String type = config.getString("shell-save-type", "").trim();
|
||||
|
@ -69,6 +69,15 @@ public class BukkitWorld extends LocalWorld {
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the world
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set block type.
|
||||
|
@ -32,6 +32,7 @@ import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||
|
||||
/**
|
||||
* Snapshot commands.
|
||||
@ -58,33 +59,37 @@ public class SnapshotCommands {
|
||||
|
||||
int num = args.argsLength() > 0 ?
|
||||
Math.min(40, Math.max(5, args.getInteger(0))) : 5;
|
||||
|
||||
String worldName = player.getWorld().getName();
|
||||
SnapshotRepository repo = config.snapshotRepositories.get(worldName);
|
||||
|
||||
if (repo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured for this world.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Snapshot> snapshots = repo.getSnapshots(true);
|
||||
|
||||
if (config.snapshotRepo != null) {
|
||||
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true);
|
||||
|
||||
if (snapshots.size() > 0) {
|
||||
for (byte i = 0; i < Math.min(num, snapshots.size()); i++) {
|
||||
player.print((i + 1) + ". " + snapshots.get(i).getName());
|
||||
}
|
||||
|
||||
player.print("Use /snap use [snapshot] or /snap use latest.");
|
||||
} else {
|
||||
player.printError("No snapshots are available. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = config.snapshotRepo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
dir.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.info("WorldEdit found no snapshots: looked in "
|
||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
||||
dir.getPath());
|
||||
}
|
||||
if (snapshots.size() > 0) {
|
||||
for (byte i = 0; i < Math.min(num, snapshots.size()); i++) {
|
||||
player.print((i + 1) + ". " + snapshots.get(i).getName());
|
||||
}
|
||||
|
||||
player.print("Use /snap use [snapshot] or /snap use latest.");
|
||||
} else {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
player.printError("No snapshots are available. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = repo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
dir.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.info("WorldEdit found no snapshots: looked in "
|
||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
||||
dir.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,9 +106,11 @@ public class SnapshotCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
String worldName = player.getWorld().getName();
|
||||
SnapshotRepository repo = config.snapshotRepositories.get(worldName);
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
if (repo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured for this world.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -111,17 +118,17 @@ public class SnapshotCommands {
|
||||
|
||||
// Want the latest snapshot?
|
||||
if (name.equalsIgnoreCase("latest")) {
|
||||
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot();
|
||||
Snapshot snapshot = repo.getDefaultSnapshot();
|
||||
|
||||
if (snapshot != null) {
|
||||
session.setSnapshot(null);
|
||||
session.setSnapshot(player.getWorld(), null);
|
||||
player.print("Now using newest snapshot.");
|
||||
} else {
|
||||
player.printError("No snapshots were found.");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
|
||||
session.setSnapshot(player.getWorld(), repo.getSnapshot(name));
|
||||
player.print("Snapshot set to: " + name);
|
||||
} catch (InvalidSnapshotException e) {
|
||||
player.printError("That snapshot does not exist or is not available.");
|
||||
@ -142,9 +149,11 @@ public class SnapshotCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
String worldName = player.getWorld().getName();
|
||||
SnapshotRepository repo = config.snapshotRepositories.get(worldName);
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
if (repo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured for this world.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -155,12 +164,12 @@ public class SnapshotCommands {
|
||||
} else {
|
||||
dateFormat.setTimeZone(session.getTimeZone());
|
||||
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date);
|
||||
Snapshot snapshot = repo.getSnapshotBefore(date);
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot before "
|
||||
+ dateFormat.format(date.getTime()) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
session.setSnapshot(player.getWorld(), snapshot);
|
||||
player.print("Snapshot set to: " + snapshot.getName());
|
||||
}
|
||||
}
|
||||
@ -179,9 +188,11 @@ public class SnapshotCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
String worldName = player.getWorld().getName();
|
||||
SnapshotRepository repo = config.snapshotRepositories.get(worldName);
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
if (repo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured for this world.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -192,12 +203,12 @@ public class SnapshotCommands {
|
||||
} else {
|
||||
dateFormat.setTimeZone(session.getTimeZone());
|
||||
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date);
|
||||
Snapshot snapshot = repo.getSnapshotAfter(date);
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot after "
|
||||
+ dateFormat.format(date.getTime()) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
session.setSnapshot(player.getWorld(), snapshot);
|
||||
player.print("Snapshot set to: " + snapshot.getName());
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRestore;
|
||||
|
||||
public class SnapshotUtilCommands {
|
||||
@ -65,9 +66,11 @@ public class SnapshotUtilCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
String worldName = player.getWorld().getName();
|
||||
SnapshotRepository repo = config.snapshotRepositories.get(worldName);
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
if (repo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured for this world.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,26 +79,26 @@ public class SnapshotUtilCommands {
|
||||
|
||||
if (args.argsLength() > 0) {
|
||||
try {
|
||||
snapshot = config.snapshotRepo.getSnapshot(args.getString(0));
|
||||
snapshot = repo.getSnapshot(args.getString(0));
|
||||
} catch (InvalidSnapshotException e) {
|
||||
player.printError("That snapshot does not exist or is not available.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
snapshot = session.getSnapshot();
|
||||
snapshot = session.getSnapshot(player.getWorld());
|
||||
}
|
||||
|
||||
ChunkStore chunkStore = null;
|
||||
|
||||
// No snapshot set?
|
||||
if (snapshot == null) {
|
||||
snapshot = config.snapshotRepo.getDefaultSnapshot();
|
||||
snapshot = repo.getDefaultSnapshot();
|
||||
|
||||
if (snapshot == null) {
|
||||
player.printError("No snapshots were found. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = config.snapshotRepo.getDirectory();
|
||||
File dir = repo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
|
@ -27,6 +27,7 @@ import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Simple LocalConfiguration that loads settings using
|
||||
@ -93,10 +94,11 @@ public class PropertiesConfiguration extends LocalConfiguration {
|
||||
LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));
|
||||
|
||||
String snapshotsDir = getString("snapshots-dir", "");
|
||||
snapshotRepositories = new HashMap();
|
||||
if (!snapshotsDir.trim().equals("")) {
|
||||
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
||||
} else {
|
||||
snapshotRepo = null;
|
||||
for (File repository : new File(snapshotsDir).listFiles()) {
|
||||
snapshotRepositories.put(repository.getName(), new SnapshotRepository(repository));
|
||||
}
|
||||
}
|
||||
|
||||
OutputStream output = null;
|
||||
|
Loading…
Reference in New Issue
Block a user