Java Code Examples for com.sk89q.worldedit.LocalSession#setSnapshot()

The following examples show how to use com.sk89q.worldedit.LocalSession#setSnapshot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnapshotCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"before"},
        usage = "<date>",
        desc = "Choose the nearest snapshot before a date",
        min = 1,
        max = -1
)
@CommandPermissions("worldedit.snapshots.restore")
public void before(Player player, LocalSession session, CommandContext args) throws WorldEditException {

    LocalConfiguration config = we.getConfiguration();

    if (config.snapshotRepo == null) {
        player.printError("Snapshot/backup restore is not configured.");
        return;
    }

    Calendar date = session.detectDate(args.getJoinedStrings(0));

    if (date == null) {
        player.printError("Could not detect the date inputted.");
    } else {
        try {
            Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date, player.getWorld().getName());

            if (snapshot == null) {
                dateFormat.setTimeZone(session.getTimeZone());
                player.printError("Couldn't find a snapshot before "
                        + dateFormat.format(date.getTime()) + ".");
            } else {
                session.setSnapshot(snapshot);
                BBC.SNAPSHOT_SET.send(player, snapshot.getName());
            }
        } catch (MissingWorldException ex) {
            player.printError("No snapshots were found for this world.");
        }
    }
}
 
Example 2
Source File: SnapshotCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"after"},
        usage = "<date>",
        desc = "Choose the nearest snapshot after a date",
        min = 1,
        max = -1
)
@CommandPermissions("worldedit.snapshots.restore")
public void after(Player player, LocalSession session, CommandContext args) throws WorldEditException {

    LocalConfiguration config = we.getConfiguration();

    if (config.snapshotRepo == null) {
        player.printError("Snapshot/backup restore is not configured.");
        return;
    }

    Calendar date = session.detectDate(args.getJoinedStrings(0));

    if (date == null) {
        player.printError("Could not detect the date inputted.");
    } else {
        try {
            Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, player.getWorld().getName());
            if (snapshot == null) {
                dateFormat.setTimeZone(session.getTimeZone());
                player.printError("Couldn't find a snapshot after " + dateFormat.format(date.getTime()) + ".");
            } else {
                session.setSnapshot(snapshot);
                BBC.SNAPSHOT_SET.send(player, snapshot.getName());
            }
        } catch (MissingWorldException ex) {
            player.printError("No snapshots were found for this world.");
        }
    }
}
 
Example 3
Source File: SnapshotCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(
        aliases = {"use"},
        usage = "<snapshot>",
        desc = "Choose a snapshot to use",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.snapshots.restore")
public void use(Player player, LocalSession session, CommandContext args) throws WorldEditException {

    LocalConfiguration config = we.getConfiguration();

    if (config.snapshotRepo == null) {
        player.printError("Snapshot/backup restore is not configured.");
        return;
    }

    String name = args.getString(0);

    // Want the latest snapshot?
    if (name.equalsIgnoreCase("latest")) {
        try {
            Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(player.getWorld().getName());

            if (snapshot != null) {
                session.setSnapshot(null);
                BBC.SNAPSHOT_NEWEST.send(player);
            } else {
                player.printError("No snapshots were found.");
            }
        } catch (MissingWorldException ex) {
            player.printError("No snapshots were found for this world.");
        }
    } else {
        try {
            session.setSnapshot(config.snapshotRepo.getSnapshot(name));
            BBC.SNAPSHOT_SET.send(player, name);
        } catch (InvalidSnapshotException e) {
            player.printError("That snapshot does not exist or is not available.");
        }
    }
}