2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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 Lesser General Public License
|
|
|
|
* for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.*;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-28 08:01:49 +00:00
|
|
|
* Commands to undo, redo, and clear history.
|
2014-04-03 02:08:50 +00:00
|
|
|
*/
|
|
|
|
public class HistoryCommands {
|
2014-06-28 08:01:49 +00:00
|
|
|
|
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public HistoryCommands(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/undo", "undo" },
|
|
|
|
usage = "[times] [player]",
|
|
|
|
desc = "Undoes the last action",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.undo")
|
2016-12-24 04:56:53 +00:00
|
|
|
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
int times = Math.max(1, args.getInteger(0, 1));
|
|
|
|
for (int i = 0; i < times; ++i) {
|
|
|
|
EditSession undone;
|
|
|
|
if (args.argsLength() < 2) {
|
|
|
|
undone = session.undo(session.getBlockBag(player), player);
|
|
|
|
} else {
|
|
|
|
player.checkPermission("worldedit.history.undo.other");
|
2014-06-28 08:01:49 +00:00
|
|
|
LocalSession sess = worldEdit.getSession(args.getString(1));
|
2014-04-03 02:08:50 +00:00
|
|
|
if (sess == null) {
|
|
|
|
player.printError("Unable to find session for " + args.getString(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
undone = sess.undo(session.getBlockBag(player), player);
|
|
|
|
}
|
|
|
|
if (undone != null) {
|
|
|
|
player.print("Undo successful.");
|
2014-06-28 08:01:49 +00:00
|
|
|
worldEdit.flushBlockBag(player, undone);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
player.printError("Nothing left to undo.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/redo", "redo" },
|
|
|
|
usage = "[times] [player]",
|
|
|
|
desc = "Redoes the last action (from history)",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.redo")
|
2016-12-24 04:56:53 +00:00
|
|
|
public void redo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
int times = Math.max(1, args.getInteger(0, 1));
|
|
|
|
|
|
|
|
for (int i = 0; i < times; ++i) {
|
|
|
|
EditSession redone;
|
|
|
|
if (args.argsLength() < 2) {
|
|
|
|
redone = session.redo(session.getBlockBag(player), player);
|
|
|
|
} else {
|
|
|
|
player.checkPermission("worldedit.history.redo.other");
|
2014-06-28 08:01:49 +00:00
|
|
|
LocalSession sess = worldEdit.getSession(args.getString(1));
|
2014-04-03 02:08:50 +00:00
|
|
|
if (sess == null) {
|
|
|
|
player.printError("Unable to find session for " + args.getString(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
redone = sess.redo(session.getBlockBag(player), player);
|
|
|
|
}
|
|
|
|
if (redone != null) {
|
|
|
|
player.print("Redo successful.");
|
2014-06-28 08:01:49 +00:00
|
|
|
worldEdit.flushBlockBag(player, redone);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
player.printError("Nothing left to redo.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/clearhistory", "clearhistory" },
|
|
|
|
usage = "",
|
|
|
|
desc = "Clear your history",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.clear")
|
2016-12-24 04:56:53 +00:00
|
|
|
public void clearHistory(Player player, LocalSession session) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.clearHistory();
|
|
|
|
player.print("History cleared.");
|
|
|
|
}
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|