2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2011-01-29 10:05:22 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.commands;
|
|
|
|
|
2011-02-18 06:53:44 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* History little commands.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class HistoryCommands {
|
2011-12-18 07:45:12 +00:00
|
|
|
private final WorldEdit we;
|
|
|
|
|
|
|
|
public HistoryCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/undo", "undo" },
|
2011-08-29 21:24:35 +00:00
|
|
|
usage = "[times] [player]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Undoes the last action",
|
|
|
|
min = 0,
|
2011-08-29 21:24:35 +00:00
|
|
|
max = 2
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.history.undo")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void undo(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-02-19 05:19:54 +00:00
|
|
|
int times = Math.max(1, args.getInteger(0, 1));
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int i = 0; i < times; ++i) {
|
2011-08-29 21:24:35 +00:00
|
|
|
EditSession undone;
|
|
|
|
if (args.argsLength() < 2) {
|
|
|
|
undone = session.undo(session.getBlockBag(player));
|
|
|
|
} else {
|
|
|
|
player.checkPermission("worldedit.history.undo.other");
|
|
|
|
LocalSession sess = we.getSession(args.getString(1));
|
2011-11-23 01:29:48 +00:00
|
|
|
if (sess == null) {
|
2011-08-29 21:24:35 +00:00
|
|
|
player.printError("Unable to find session for " + args.getString(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
undone = sess.undo(session.getBlockBag(player));
|
|
|
|
}
|
2011-02-19 05:19:54 +00:00
|
|
|
if (undone != null) {
|
|
|
|
player.print("Undo successful.");
|
|
|
|
we.flushBlockBag(player, undone);
|
|
|
|
} else {
|
|
|
|
player.printError("Nothing left to undo.");
|
|
|
|
break;
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/redo", "redo" },
|
2011-08-29 21:24:35 +00:00
|
|
|
usage = "[times] [player]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Redoes the last action (from history)",
|
|
|
|
min = 0,
|
2011-08-29 21:24:35 +00:00
|
|
|
max = 2
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.history.redo")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void redo(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-02-19 05:19:54 +00:00
|
|
|
|
|
|
|
int times = Math.max(1, args.getInteger(0, 1));
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int i = 0; i < times; ++i) {
|
2011-08-29 21:24:35 +00:00
|
|
|
EditSession redone;
|
|
|
|
if (args.argsLength() < 2) {
|
|
|
|
redone = session.redo(session.getBlockBag(player));
|
|
|
|
} else {
|
|
|
|
player.checkPermission("worldedit.history.redo.other");
|
|
|
|
LocalSession sess = we.getSession(args.getString(1));
|
2011-11-23 01:29:48 +00:00
|
|
|
if (sess == null) {
|
2011-08-29 21:24:35 +00:00
|
|
|
player.printError("Unable to find session for " + args.getString(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
redone = sess.redo(session.getBlockBag(player));
|
|
|
|
}
|
2011-02-19 05:19:54 +00:00
|
|
|
if (redone != null) {
|
|
|
|
player.print("Redo successful.");
|
|
|
|
we.flushBlockBag(player, redone);
|
|
|
|
} else {
|
|
|
|
player.printError("Nothing left to redo.");
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/clearhistory", "clearhistory" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "",
|
|
|
|
desc = "Clear your history",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.history.clear")
|
2011-12-18 07:45:12 +00:00
|
|
|
public void clearHistory(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
session.clearHistory();
|
|
|
|
player.print("History cleared.");
|
|
|
|
}
|
|
|
|
}
|