From 56d69f9e77a1252dd65b4f618f78cea1ea9e6911 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 23 Jan 2011 02:09:51 -0800 Subject: [PATCH] Added /s to repeat last script. --- plugin.yml | 3 +++ src/com/sk89q/worldedit/LocalSession.java | 15 +++++++++++++ .../sk89q/worldedit/WorldEditController.java | 22 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/plugin.yml b/plugin.yml index 45102f9e4..052f29cf0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -250,6 +250,9 @@ commands: cs: description: Execute a CraftScript usage: / [arg1 [args2 [arg3 [...]]]] + s: + description: Re-execute last CraftScript + usage: / [arg1 [args2 [arg3 [...]]]] reloadwe: description: Reload WorldEdit's configuration diff --git a/src/com/sk89q/worldedit/LocalSession.java b/src/com/sk89q/worldedit/LocalSession.java index 23b0bb6b1..a36337371 100644 --- a/src/com/sk89q/worldedit/LocalSession.java +++ b/src/com/sk89q/worldedit/LocalSession.java @@ -48,6 +48,7 @@ public class LocalSession { private int maxBlocksChanged = -1; private boolean useInventory; private Snapshot snapshot; + private String lastScript; /** * Clear history. @@ -412,4 +413,18 @@ public class LocalSession { public void setUseInventory(boolean useInventory) { this.useInventory = useInventory; } + + /** + * @return the lastScript + */ + public String getLastScript() { + return lastScript; + } + + /** + * @param lastScript the lastScript to set + */ + public void setLastScript(String lastScript) { + this.lastScript = lastScript; + } } diff --git a/src/com/sk89q/worldedit/WorldEditController.java b/src/com/sk89q/worldedit/WorldEditController.java index 60bf5880a..bf2918f0d 100644 --- a/src/com/sk89q/worldedit/WorldEditController.java +++ b/src/com/sk89q/worldedit/WorldEditController.java @@ -178,6 +178,7 @@ public class WorldEditController { commands.put("/rbrush", "[ID] - Switch to the replacing sphere brush tool"); commands.put("/cs", "[Filename] - Execute a CraftScript"); + commands.put("/s", " - Re-execute last CraftScript"); } /** @@ -1714,8 +1715,29 @@ public class WorldEditController { String[] args = new String[split.length - 1]; System.arraycopy(split, 1, args, 0, split.length - 1); + session.setLastScript(split[1]); + runScript(player, split[1], args); + return true; + + // CraftScript + } else if (split[0].equalsIgnoreCase("/s")) { + checkArgs(split, 1, -1, split[0]); + + String lastScript = session.getLastScript(); + + if (lastScript == null) { + player.printError("Use /cs with a script name first."); + return true; + } + + String[] args = new String[split.length]; + System.arraycopy(split, 0, args, 0, split.length); + args[0] = lastScript; + + runScript(player, lastScript, args); + return true; }