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;
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
2019-11-21 06:50:37 +00:00
|
|
|
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2019-10-23 16:58:36 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2019-10-13 11:47:26 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2019-11-23 04:31:48 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
2019-07-06 00:46:48 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
2019-07-21 11:39:36 +00:00
|
|
|
|
2019-04-23 22:35:05 +00:00
|
|
|
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-07-06 00:46:48 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2019-07-25 18:44:10 +00:00
|
|
|
public class HistoryCommands {
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2019-07-21 11:39:36 +00:00
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public HistoryCommands(WorldEdit worldEdit) {
|
2019-07-21 11:39:36 +00:00
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2020-01-26 18:01:16 +00:00
|
|
|
name = "undo",
|
|
|
|
aliases = { "/undo" },
|
2020-02-06 21:33:31 +00:00
|
|
|
desc = "Undoes the last action (from history)"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"})
|
2020-01-26 18:01:16 +00:00
|
|
|
public void undo(Player player, LocalSession session,
|
2019-11-21 06:50:37 +00:00
|
|
|
@Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of undoes to perform", def = "1")
|
2020-02-06 21:33:31 +00:00
|
|
|
int times,
|
2019-11-20 00:11:54 +00:00
|
|
|
@Arg(name = "player", desc = "Undo this player's operations", def = "")
|
2020-02-06 21:33:31 +00:00
|
|
|
String playerName) throws WorldEditException {
|
2019-07-25 18:44:10 +00:00
|
|
|
times = Math.max(1, times);
|
2019-11-21 07:57:32 +00:00
|
|
|
LocalSession undoSession = session;
|
2019-04-05 13:53:00 +00:00
|
|
|
if (session.hasFastMode()) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.print(TranslatableComponent.of("fawe.worldedit.history.command.undo.disabled"));
|
2019-04-05 13:53:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-21 07:57:32 +00:00
|
|
|
if (playerName != null) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.checkPermission("worldedit.history.undo.other");
|
2019-07-17 16:31:13 +00:00
|
|
|
undoSession = worldEdit.getSessionManager().findByName(playerName);
|
|
|
|
if (undoSession == null) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName)));
|
2019-07-17 16:31:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|
2019-11-21 07:57:32 +00:00
|
|
|
int timesUndone = 0;
|
|
|
|
for (int i = 0; i < times; ++i) {
|
2020-01-26 18:01:16 +00:00
|
|
|
EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player);
|
2019-11-21 07:57:32 +00:00
|
|
|
if (undone != null) {
|
|
|
|
timesUndone++;
|
2020-01-26 18:01:16 +00:00
|
|
|
worldEdit.flushBlockBag(player, undone);
|
2019-11-21 07:57:32 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|
2019-11-21 07:57:32 +00:00
|
|
|
if (timesUndone > 0) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.undo.undone", TextComponent.of(timesUndone)));
|
2019-11-21 07:57:32 +00:00
|
|
|
} else {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.undo.none"));
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2020-01-26 18:01:16 +00:00
|
|
|
name = "redo",
|
|
|
|
aliases = { "/redo" },
|
2019-07-06 00:46:48 +00:00
|
|
|
desc = "Redoes the last action (from history)"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"})
|
2020-01-26 18:01:16 +00:00
|
|
|
public void redo(Player player, LocalSession session,
|
2019-11-21 06:50:37 +00:00
|
|
|
@Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of redoes to perform", def = "1")
|
2019-07-06 00:46:48 +00:00
|
|
|
int times,
|
|
|
|
@Arg(name = "player", desc = "Redo this player's operations", def = "")
|
|
|
|
String playerName) throws WorldEditException {
|
|
|
|
times = Math.max(1, times);
|
|
|
|
LocalSession redoSession = session;
|
|
|
|
if (playerName != null) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.checkPermission("worldedit.history.redo.other");
|
2019-07-06 00:46:48 +00:00
|
|
|
redoSession = worldEdit.getSessionManager().findByName(playerName);
|
|
|
|
if (redoSession == null) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName)));
|
2019-07-06 00:46:48 +00:00
|
|
|
return;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2018-10-13 04:21:39 +00:00
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
int timesRedone = 0;
|
|
|
|
for (int i = 0; i < times; ++i) {
|
2020-01-26 18:01:16 +00:00
|
|
|
EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player);
|
2019-07-06 00:46:48 +00:00
|
|
|
if (redone != null) {
|
|
|
|
timesRedone++;
|
2020-01-26 18:01:16 +00:00
|
|
|
worldEdit.flushBlockBag(player, redone);
|
2019-07-06 00:46:48 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2018-10-13 04:21:39 +00:00
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
if (timesRedone > 0) {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.redo.redone", TextComponent.of(timesRedone)));
|
2019-07-06 00:46:48 +00:00
|
|
|
} else {
|
2020-01-26 18:01:16 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.redo.none"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2020-02-06 21:33:31 +00:00
|
|
|
name = "clearhistory",
|
|
|
|
aliases = { "/clearhistory" },
|
|
|
|
desc = "Clear your history"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.history.clear")
|
2019-10-23 16:58:36 +00:00
|
|
|
public void clearHistory(Actor actor, LocalSession session) {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.clearHistory();
|
2019-10-13 11:47:26 +00:00
|
|
|
actor.printInfo(TranslatableComponent.of("worldedit.clearhistory.cleared"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2020-02-06 21:33:31 +00:00
|
|
|
|
2019-06-12 21:12:12 +00:00
|
|
|
}
|