From 20da6227d474562796d184c0fd410b573c54f8f0 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 23 Apr 2019 15:35:05 -0700 Subject: [PATCH] Port history commands --- .../worldedit/command/HistoryCommands.java | 82 ++++++++++--------- .../platform/PlatformCommandMananger.java | 7 ++ 2 files changed, 49 insertions(+), 40 deletions(-) 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 b960dfbe4..b9a247132 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 @@ -19,20 +19,23 @@ package com.sk89q.worldedit.command; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.sk89q.minecraft.util.commands.Command; -import com.sk89q.minecraft.util.commands.CommandContext; -import com.sk89q.minecraft.util.commands.CommandPermissions; 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; import com.sk89q.worldedit.entity.Player; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; +import org.enginehub.piston.annotation.param.Arg; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Commands to undo, redo, and clear history. */ +@CommandContainer(superTypes = CommandPermissionsConditionGenerator.class) public class HistoryCommands { private final WorldEdit worldEdit; @@ -48,28 +51,29 @@ public class HistoryCommands { } @Command( - aliases = { "/undo", "undo" }, - usage = "[times] [player]", - desc = "Undoes the last action", - min = 0, - max = 2 + name = "undo", + aliases = { "/undo" }, + desc = "Undoes the last action (from history)" ) @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, + @Arg(desc = "Number of undoes to perform", def = "1") + int times, + @Arg(name = "player", desc = "Undo this player's operations", def = "") + String playerName) throws WorldEditException { + times = Math.max(1, times); for (int i = 0; i < times; ++i) { - EditSession undone; - if (args.argsLength() < 2) { - undone = session.undo(session.getBlockBag(player), player); - } else { + LocalSession undoSession = session; + if (playerName != null) { player.checkPermission("worldedit.history.undo.other"); - LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1)); + LocalSession sess = worldEdit.getSessionManager().findByName(playerName); if (sess == null) { - player.printError("Unable to find session for " + args.getString(1)); + player.printError("Unable to find session for " + playerName); break; } - undone = sess.undo(session.getBlockBag(player), player); + undoSession = session; } + EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player); if (undone != null) { player.print("Undo successful."); worldEdit.flushBlockBag(player, undone); @@ -81,45 +85,43 @@ public class HistoryCommands { } @Command( - aliases = { "/redo", "redo" }, - usage = "[times] [player]", - desc = "Redoes the last action (from history)", - min = 0, - max = 2 + name = "redo", + aliases = { "redo" }, + desc = "Redoes the last action (from history)" ) @CommandPermissions("worldedit.history.redo") - public void redo(Player player, LocalSession session, CommandContext args) throws WorldEditException { - - int times = Math.max(1, args.getInteger(0, 1)); - + public void redo(Player player, LocalSession session, + @Arg(desc = "Number of redoes to perform", def = "1") + int times, + @Arg(name = "player", desc = "Redo this player's operations", def = "") + String playerName) throws WorldEditException { + times = Math.max(1, times); for (int i = 0; i < times; ++i) { - EditSession redone; - if (args.argsLength() < 2) { - redone = session.redo(session.getBlockBag(player), player); - } else { + LocalSession redoSession = session; + if (playerName != null) { player.checkPermission("worldedit.history.redo.other"); - LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1)); + LocalSession sess = worldEdit.getSessionManager().findByName(playerName); if (sess == null) { - player.printError("Unable to find session for " + args.getString(1)); + player.printError("Unable to find session for " + playerName); break; } - redone = sess.redo(session.getBlockBag(player), player); + redoSession = session; } + EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player); if (redone != null) { player.print("Redo successful."); worldEdit.flushBlockBag(player, redone); } else { player.printError("Nothing left to redo."); + break; } } } @Command( - aliases = { "/clearhistory", "clearhistory" }, - usage = "", - desc = "Clear your history", - min = 0, - max = 0 + name = "clearhistory", + aliases = { "/clearhistory" }, + desc = "Clear your history" ) @CommandPermissions("worldedit.history.clear") public void clearHistory(Player player, LocalSession session) throws WorldEditException { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java index d40c2e39e..8f0e0a8d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandMananger.java @@ -38,6 +38,8 @@ import com.sk89q.worldedit.command.GeneralCommands; import com.sk89q.worldedit.command.GeneralCommandsRegistration; import com.sk89q.worldedit.command.GenerationCommands; import com.sk89q.worldedit.command.GenerationCommandsRegistration; +import com.sk89q.worldedit.command.HistoryCommands; +import com.sk89q.worldedit.command.HistoryCommandsRegistration; import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommandsRegistration; import com.sk89q.worldedit.command.argument.Arguments; @@ -277,6 +279,11 @@ public final class PlatformCommandMananger { GenerationCommandsRegistration.builder(), new GenerationCommands(worldEdit) ); + register( + commandManager, + HistoryCommandsRegistration.builder(), + new HistoryCommands(worldEdit) + ); // Unported commands are below. Delete once they're added to the main manager above. /*