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 {
@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;
@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 {
if (command == null || getMeta("cmdConfirmRunning", false)) {
return;

View File

@ -47,16 +47,11 @@ import java.io.File;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* 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)")
public class HistoryCommands {
private final WorldEdit worldEdit;
public class HistoryCommands extends MethodCommands {
/**
* Create a new instance.
@ -64,8 +59,7 @@ public class HistoryCommands {
* @param worldEdit reference to WorldEdit
*/
public HistoryCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
super(worldEdit);
}
@Command(
@ -217,17 +211,20 @@ public class HistoryCommands {
max = 2
)
@CommandPermissions("worldedit.history.undo")
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1));
public void undo(Player player, LocalSession session, CommandContext context) throws WorldEditException {
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) {
EditSession undone;
if (args.argsLength() < 2) {
if (context.argsLength() < 2) {
undone = session.undo(session.getBlockBag(player), player);
} else {
player.checkPermission("worldedit.history.undo.other");
LocalSession sess = worldEdit.getSession(args.getString(1));
LocalSession sess = worldEdit.getSession(context.getString(1));
if (sess == null) {
BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, args.getString(1));
BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, context.getString(1));
break;
}
undone = sess.undo(session.getBlockBag(player), player);