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> usage: /<command>
/redo: /redo:
description: Redoes the last action (from history) description: Redoes the last action (from history)
usage: /<command> usage: /<command> [times]
/undo: /undo:
description: Undoes the last action description: Undoes the last action
usage: /<command> usage: /<command> [times]
unstuck: unstuck:
description: Escape from being stuck inside a block description: Escape from being stuck inside a block
usage: /<command> usage: /<command>

View File

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

View File

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