Confirm for large `\\undo <times>`

This commit is contained in:
Jesse Boyd 2018-03-10 14:36:53 +11:00
parent a19e9a45e9
commit 4a9721edd3
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 22 additions and 14 deletions

View File

@ -319,7 +319,8 @@ public class Settings extends Config {
public static class WEB { public static class WEB {
@Comment({ @Comment({
"Should download urls be shortened?" "Should download urls be shortened?",
" - Links are less secure as they could be brute forced"
}) })
public boolean SHORTEN_URLS = false; public boolean SHORTEN_URLS = false;
@Comment({ @Comment({

View File

@ -122,6 +122,16 @@ public abstract class FawePlayer<T> extends Metadatable {
} }
} }
public void checkConfirmation(String command, int times, int limit) throws RegionOperationException {
if (command == null || getMeta("cmdConfirmRunning", false)) {
return;
}
if (times > limit) {
setMeta("cmdConfirm", command);
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(0, times, command));
}
}
public void checkConfirmationRadius(String command, int radius) throws RegionOperationException { public void checkConfirmationRadius(String command, int radius) throws RegionOperationException {
if (command == null || getMeta("cmdConfirmRunning", false)) { if (command == null || getMeta("cmdConfirmRunning", false)) {
return; return;

View File

@ -47,16 +47,11 @@ import java.io.File;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Commands to undo, redo, and clear history. * Commands to undo, redo, and clear history.
*/ */
@Command(aliases = {}, desc = "Commands to undo, redo, and clear history: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Features#History)") @Command(aliases = {}, desc = "Commands to undo, redo, and clear history: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Features#History)")
public class HistoryCommands { public class HistoryCommands extends MethodCommands {
private final WorldEdit worldEdit;
/** /**
* Create a new instance. * Create a new instance.
@ -64,8 +59,7 @@ public class HistoryCommands {
* @param worldEdit reference to WorldEdit * @param worldEdit reference to WorldEdit
*/ */
public HistoryCommands(WorldEdit worldEdit) { public HistoryCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit); super(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -217,17 +211,20 @@ public class HistoryCommands {
max = 2 max = 2
) )
@CommandPermissions("worldedit.history.undo") @CommandPermissions("worldedit.history.undo")
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void undo(Player player, LocalSession session, CommandContext context) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1)); int times = Math.max(1, context.getInteger(0, 1));
if (times > 50) {
FawePlayer.wrap(player).checkConfirmation(getArguments(context), times, 50);
}
for (int i = 0; i < times; ++i) { for (int i = 0; i < times; ++i) {
EditSession undone; EditSession undone;
if (args.argsLength() < 2) { if (context.argsLength() < 2) {
undone = session.undo(session.getBlockBag(player), player); undone = session.undo(session.getBlockBag(player), player);
} else { } else {
player.checkPermission("worldedit.history.undo.other"); player.checkPermission("worldedit.history.undo.other");
LocalSession sess = worldEdit.getSession(args.getString(1)); LocalSession sess = worldEdit.getSession(context.getString(1));
if (sess == null) { if (sess == null) {
BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, args.getString(1)); BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, context.getString(1));
break; break;
} }
undone = sess.undo(session.getBlockBag(player), player); undone = sess.undo(session.getBlockBag(player), player);