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;
|
|
|
|
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-04-23 22:35:05 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2019-04-23 22:35:05 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-06-28 08:01:49 +00:00
|
|
|
|
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
|
|
|
*/
|
2019-04-23 22:35:05 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.class)
|
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(
|
2019-04-23 22:35:05 +00:00
|
|
|
name = "undo",
|
|
|
|
aliases = { "/undo" },
|
|
|
|
desc = "Undoes the last action (from history)"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.undo")
|
2019-04-23 22:35:05 +00:00
|
|
|
public void undo(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Number of undoes to perform", def = "1")
|
|
|
|
int times,
|
|
|
|
@Arg(name = "player", desc = "Undo this player's operations", def = "")
|
|
|
|
String playerName) throws WorldEditException {
|
|
|
|
times = Math.max(1, times);
|
2014-04-03 02:08:50 +00:00
|
|
|
for (int i = 0; i < times; ++i) {
|
2019-04-23 22:35:05 +00:00
|
|
|
LocalSession undoSession = session;
|
|
|
|
if (playerName != null) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.checkPermission("worldedit.history.undo.other");
|
2019-04-23 22:35:05 +00:00
|
|
|
LocalSession sess = worldEdit.getSessionManager().findByName(playerName);
|
2014-04-03 02:08:50 +00:00
|
|
|
if (sess == null) {
|
2019-04-23 22:35:05 +00:00
|
|
|
player.printError("Unable to find session for " + playerName);
|
2014-04-03 02:08:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 22:35:05 +00:00
|
|
|
undoSession = session;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-04-23 22:35:05 +00:00
|
|
|
EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player);
|
2014-04-03 02:08:50 +00:00
|
|
|
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(
|
2019-04-23 22:35:05 +00:00
|
|
|
name = "redo",
|
|
|
|
aliases = { "redo" },
|
|
|
|
desc = "Redoes the last action (from history)"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.redo")
|
2019-04-23 22:35:05 +00:00
|
|
|
public void redo(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Number of redoes to perform", def = "1")
|
|
|
|
int times,
|
|
|
|
@Arg(name = "player", desc = "Redo this player's operations", def = "")
|
|
|
|
String playerName) throws WorldEditException {
|
|
|
|
times = Math.max(1, times);
|
2014-04-03 02:08:50 +00:00
|
|
|
for (int i = 0; i < times; ++i) {
|
2019-04-23 22:35:05 +00:00
|
|
|
LocalSession redoSession = session;
|
|
|
|
if (playerName != null) {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.checkPermission("worldedit.history.redo.other");
|
2019-04-23 22:35:05 +00:00
|
|
|
LocalSession sess = worldEdit.getSessionManager().findByName(playerName);
|
2014-04-03 02:08:50 +00:00
|
|
|
if (sess == null) {
|
2019-04-23 22:35:05 +00:00
|
|
|
player.printError("Unable to find session for " + playerName);
|
2014-04-03 02:08:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-23 22:35:05 +00:00
|
|
|
redoSession = session;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-04-23 22:35:05 +00:00
|
|
|
EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player);
|
2014-04-03 02:08:50 +00:00
|
|
|
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.");
|
2019-04-23 22:35:05 +00:00
|
|
|
break;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-23 22:35:05 +00:00
|
|
|
name = "clearhistory",
|
|
|
|
aliases = { "/clearhistory" },
|
|
|
|
desc = "Clear your history"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.clear")
|
2019-03-16 23:04:24 +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
|
|
|
}
|