Clean up/fix undo/redo. Add separate .self perm nodes.

This commit is contained in:
wizjany 2019-06-16 10:09:35 -04:00
parent 61fd44fa8c
commit dcd1d8d0bc

View File

@ -55,33 +55,37 @@ public class HistoryCommands {
aliases = { "/undo" }, aliases = { "/undo" },
desc = "Undoes the last action (from history)" desc = "Undoes the last action (from history)"
) )
@CommandPermissions("worldedit.history.undo") @CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"})
public void undo(Player player, LocalSession session, public void undo(Player player, LocalSession session,
@Arg(desc = "Number of undoes to perform", def = "1") @Arg(desc = "Number of undoes to perform", def = "1")
int times, int times,
@Arg(name = "player", desc = "Undo this player's operations", def = "") @Arg(name = "player", desc = "Undo this player's operations", def = "")
String playerName) throws WorldEditException { String playerName) throws WorldEditException {
times = Math.max(1, times); times = Math.max(1, times);
for (int i = 0; i < times; ++i) {
LocalSession undoSession = session; LocalSession undoSession = session;
if (playerName != null) { if (playerName != null) {
player.checkPermission("worldedit.history.undo.other"); player.checkPermission("worldedit.history.undo.other");
LocalSession sess = worldEdit.getSessionManager().findByName(playerName); undoSession = worldEdit.getSessionManager().findByName(playerName);
if (sess == null) { if (undoSession == null) {
player.printError("Unable to find session for " + playerName); player.printError("Unable to find session for " + playerName);
break; return;
} }
undoSession = session;
} }
int timesUndone = 0;
for (int i = 0; i < times; ++i) {
EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player); EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player);
if (undone != null) { if (undone != null) {
player.print("Undo successful."); timesUndone++;
worldEdit.flushBlockBag(player, undone); worldEdit.flushBlockBag(player, undone);
} else { } else {
player.printError("Nothing left to undo.");
break; break;
} }
} }
if (timesUndone > 0) {
player.print("Undid " + timesUndone + " available edits.");
} else {
player.printError("Nothing left to undo.");
}
} }
@Command( @Command(
@ -89,33 +93,37 @@ public class HistoryCommands {
aliases = { "/redo" }, aliases = { "/redo" },
desc = "Redoes the last action (from history)" desc = "Redoes the last action (from history)"
) )
@CommandPermissions("worldedit.history.redo") @CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"})
public void redo(Player player, LocalSession session, public void redo(Player player, LocalSession session,
@Arg(desc = "Number of redoes to perform", def = "1") @Arg(desc = "Number of redoes to perform", def = "1")
int times, int times,
@Arg(name = "player", desc = "Redo this player's operations", def = "") @Arg(name = "player", desc = "Redo this player's operations", def = "")
String playerName) throws WorldEditException { String playerName) throws WorldEditException {
times = Math.max(1, times); times = Math.max(1, times);
for (int i = 0; i < times; ++i) {
LocalSession redoSession = session; LocalSession redoSession = session;
if (playerName != null) { if (playerName != null) {
player.checkPermission("worldedit.history.redo.other"); player.checkPermission("worldedit.history.redo.other");
LocalSession sess = worldEdit.getSessionManager().findByName(playerName); redoSession = worldEdit.getSessionManager().findByName(playerName);
if (sess == null) { if (redoSession == null) {
player.printError("Unable to find session for " + playerName); player.printError("Unable to find session for " + playerName);
break; return;
} }
redoSession = session;
} }
int timesRedone = 0;
for (int i = 0; i < times; ++i) {
EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player); EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player);
if (redone != null) { if (redone != null) {
player.print("Redo successful."); timesRedone++;
worldEdit.flushBlockBag(player, redone); worldEdit.flushBlockBag(player, redone);
} else { } else {
player.printError("Nothing left to redo.");
break; break;
} }
} }
if (timesRedone > 0) {
player.print("Redid " + timesRedone + " available edits.");
} else {
player.printError("Nothing left to redo.");
}
} }
@Command( @Command(
@ -124,7 +132,7 @@ public class HistoryCommands {
desc = "Clear your history" desc = "Clear your history"
) )
@CommandPermissions("worldedit.history.clear") @CommandPermissions("worldedit.history.clear")
public void clearHistory(Player player, LocalSession session) throws WorldEditException { public void clearHistory(Player player, LocalSession session) {
session.clearHistory(); session.clearHistory();
player.print("History cleared."); player.print("History cleared.");
} }