From 888cbcedeedaf54168f889905d9b59bd41c4b95d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 13 Oct 2018 15:21:39 +1100 Subject: [PATCH] tweak undo message --- .../main/java/com/boydti/fawe/config/BBC.java | 4 +- .../worldedit/command/HistoryCommands.java | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java b/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java index 6725a1080..9470e0e35 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java @@ -90,9 +90,9 @@ public enum BBC { COMMAND_HISTORY_CLEAR("History cleared", "WorldEdit.History"), COMMAND_REDO_ERROR("Nothing left to redo. (See also `/inspect` and `/frb`)", "WorldEdit.History"), COMMAND_HISTORY_OTHER_ERROR("Unable to find session for %s0.", "WorldEdit.History"), - COMMAND_REDO_SUCCESS("Redo successful.", "WorldEdit.History"), + COMMAND_REDO_SUCCESS("Redo successful%s0.", "WorldEdit.History"), COMMAND_UNDO_ERROR("Nothing left to undo. (See also `/inspect` and `/frb`)", "WorldEdit.History"), - COMMAND_UNDO_SUCCESS("Undo successful.", "WorldEdit.History"), + COMMAND_UNDO_SUCCESS("Undo successful%s0.", "WorldEdit.History"), OPERATION("Operation queued (%s0)", "WorldEdit.Operation"), diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 10f5cecc8..76e734dd0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -226,8 +226,9 @@ public class HistoryCommands extends MethodCommands { public void undo(Player player, LocalSession session, CommandContext context) throws WorldEditException { int times = Math.max(1, context.getInteger(0, 1)); FawePlayer.wrap(player).checkConfirmation(() -> { - for (int i = 0; i < times; ++i) { - EditSession undone; + EditSession undone = null; + int i = 0; + for (; i < times; ++i) { if (context.argsLength() < 2) { undone = session.undo(session.getBlockBag(player), player); } else { @@ -238,14 +239,16 @@ public class HistoryCommands extends MethodCommands { break; } undone = sess.undo(session.getBlockBag(player), player); + if (undone == null) break; } - if (undone != null) { - BBC.COMMAND_UNDO_SUCCESS.send(player); - worldEdit.flushBlockBag(player, undone); - } else { - BBC.COMMAND_UNDO_ERROR.send(player); - break; - } + } + if (undone == null) i--; + if (i > 0) { + BBC.COMMAND_UNDO_SUCCESS.send(player, i == 1 ? "" : " x" + i); + worldEdit.flushBlockBag(player, undone); + } + if (undone == null) { + BBC.COMMAND_UNDO_ERROR.send(player); } }, getArguments(context), times, 50, context); } @@ -262,8 +265,9 @@ public class HistoryCommands extends MethodCommands { int times = Math.max(1, args.getInteger(0, 1)); - for (int i = 0; i < times; ++i) { - EditSession redone; + EditSession redone = null; + int i = 0; + for (; i < times; ++i) { if (args.argsLength() < 2) { redone = session.redo(session.getBlockBag(player), player); } else { @@ -274,13 +278,16 @@ public class HistoryCommands extends MethodCommands { break; } redone = sess.redo(session.getBlockBag(player), player); + if (redone == null) break; } - if (redone != null) { - BBC.COMMAND_REDO_SUCCESS.send(player); - worldEdit.flushBlockBag(player, redone); - } else { - BBC.COMMAND_REDO_ERROR.send(player); - } + } + if (redone == null) i--; + if (i > 0) { + BBC.COMMAND_REDO_SUCCESS.send(player, i == 1 ? "" : " x" + i); + worldEdit.flushBlockBag(player, redone); + } + if (redone == null) { + BBC.COMMAND_REDO_ERROR.send(player); } }