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

The following examples show how to use com.sk89q.worldedit.LocalSession#detectDate() . 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.");
        }
    }
}