Added multiple undo/redo, fixed compile error.

This commit is contained in:
sk89q 2011-02-18 21:19:54 -08:00
parent abaeaa99ac
commit 7088fadab8
3 changed files with 31 additions and 22 deletions

View File

@ -80,10 +80,10 @@ commands:
usage: /<command>
/redo:
description: Redoes the last action (from history)
usage: /<command>
usage: /<command> [times]
/undo:
description: Undoes the last action
usage: /<command>
usage: /<command> [times]
unstuck:
description: Escape from being stuck inside a block
usage: /<command>

View File

@ -47,9 +47,9 @@ import com.sk89q.worldedit.regions.Region;
public class WorldEditPlugin extends JavaPlugin {
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
private final ServerInterface server;
private final WorldEdit controller;
private final WorldEditAPI api;
final ServerInterface server;
final WorldEdit controller;
final WorldEditAPI api;
private final LocalConfiguration config;
private final PermissionsResolverManager perms;

View File

@ -32,43 +32,52 @@ import com.sk89q.worldedit.*;
public class HistoryCommands {
@Command(
aliases = {"/undo"},
usage = "",
usage = "[times]",
desc = "Undoes the last action",
min = 0,
max = 0
max = 1
)
@CommandPermissions({"worldedit.history.undo"})
public static void undo(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
EditSession undone = session.undo(session.getBlockBag(player));
if (undone != null) {
player.print("Undo successful.");
we.flushBlockBag(player, undone);
} else {
player.printError("Nothing to undo.");
int times = Math.max(1, args.getInteger(0, 1));
for (int i = 0; i < times; i++) {
EditSession undone = session.undo(session.getBlockBag(player));
if (undone != null) {
player.print("Undo successful.");
we.flushBlockBag(player, undone);
} else {
player.printError("Nothing left to undo.");
break;
}
}
}
@Command(
aliases = {"/redo"},
usage = "",
usage = "[times]",
desc = "Redoes the last action (from history)",
min = 0,
max = 0
max = 1
)
@CommandPermissions({"worldedit.history.redo"})
public static void redo(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
EditSession redone = session.redo(session.getBlockBag(player));
if (redone != null) {
player.print("Redo successful.");
we.flushBlockBag(player, redone);
} else {
player.printError("Nothing to redo.");
int times = Math.max(1, args.getInteger(0, 1));
for (int i = 0; i < times; i++) {
EditSession redone = session.redo(session.getBlockBag(player));
if (redone != null) {
player.print("Redo successful.");
we.flushBlockBag(player, redone);
} else {
player.printError("Nothing left to redo.");
}
}
}