diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 388921536..b2e985b81 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -41,6 +41,7 @@ public class WorldEdit extends Plugin { private PropertiesFile properties; private String[] allowedBlocks; + private boolean mapScriptCommands = false; /** * Construct an instance of the plugin. @@ -65,7 +66,7 @@ public WorldEdit() { commands.put("/editload", "[Filename] - Load .schematic into clipboard"); commands.put("/editsave", "[Filename] - Save clipboard to .schematic"); commands.put("/editfill", " - Fill a hole"); - commands.put("/script", "[Filename] - Run a WorldEdit script"); + commands.put("/editscript", "[Filename] - Run a WorldEdit script"); } /** @@ -166,6 +167,7 @@ public void enable() { } allowedBlocks = properties.getString("allowed-blocks", DEFAULT_ALLOWED_BLOCKS).split(","); + mapScriptCommands = properties.getBoolean("map-script-commands", true); etc controller = etc.getInstance(); @@ -200,6 +202,21 @@ public boolean onCommand(Player player, String[] split) { if (etc.getInstance().canUseCommand(player.getName(), split[0])) { return handleEditCommand(player, split); } + } else { + // See if there is a script by the same name + if (mapScriptCommands) { + if (etc.getInstance().canUseCommand(player.getName(), "/editscript")) { + String filename = split[0].substring(1) + ".js"; + String[] args = new String[split.length - 1]; + System.arraycopy(split, 1, args, 0, split.length - 1); + try { + return runScript(player, getSession(player), new EditSession(), + filename, args); + } catch (NoSuchScriptException nse) { + return false; + } + } + } } return false; @@ -418,13 +435,17 @@ private boolean handleEditCommand(Player player, String[] split) return true; - // Run an editscript - } else if (split[0].equalsIgnoreCase("/script")) { + // Run a script + } else if (split[0].equalsIgnoreCase("/editscript")) { checkArgs(split, 1); String filename = split[1].replace("\0", "") + ".js"; String[] args = new String[split.length - 2]; System.arraycopy(split, 2, args, 0, split.length - 2); - runScript(player, session, editSession, filename, args); + try { + runScript(player, session, editSession, filename, args); + } catch (NoSuchScriptException e) { + player.sendMessage(Colors.Rose + "Script file does not exist."); + } return true; } @@ -612,7 +633,8 @@ private int fillY(EditSession editSession, int x, int cy, * @param args */ private boolean runScript(Player player, WorldEditSession session, - EditSession editSession, String filename, String[] args) { + EditSession editSession, String filename, String[] args) throws + NoSuchScriptException { File dir = new File("editscripts"); File f = new File("editscripts", filename); @@ -621,9 +643,9 @@ private boolean runScript(Player player, WorldEditSession session, String dirPath = dir.getCanonicalPath(); if (!filePath.substring(0, dirPath.length()).equals(dirPath)) { - player.sendMessage(Colors.Rose + "Script file does not exist."); + throw new NoSuchScriptException(); } else if (!f.exists()) { - player.sendMessage(Colors.Rose + "Script file does not exist."); + throw new NoSuchScriptException(); } else { // Read file StringBuffer buffer = new StringBuffer(); diff --git a/src/com/sk89q/worldedit/DisallowedItemException.java b/src/com/sk89q/worldedit/DisallowedItemException.java index ddad75506..f4fb945f3 100644 --- a/src/com/sk89q/worldedit/DisallowedItemException.java +++ b/src/com/sk89q/worldedit/DisallowedItemException.java @@ -1,5 +1,3 @@ -package com.sk89q.worldedit; - // $Id$ /* * WorldEdit @@ -19,6 +17,8 @@ * along with this program. If not, see . */ +package com.sk89q.worldedit; + /** * * @author sk89q diff --git a/src/com/sk89q/worldedit/IncompleteRegionException.java b/src/com/sk89q/worldedit/IncompleteRegionException.java index 61302a750..3b1ddea96 100644 --- a/src/com/sk89q/worldedit/IncompleteRegionException.java +++ b/src/com/sk89q/worldedit/IncompleteRegionException.java @@ -1,5 +1,3 @@ -package com.sk89q.worldedit; - // $Id$ /* * WorldEdit @@ -19,6 +17,8 @@ * along with this program. If not, see . */ +package com.sk89q.worldedit; + /** * Raised when a region is not fully defined. * diff --git a/src/com/sk89q/worldedit/InsufficientArgumentsException.java b/src/com/sk89q/worldedit/InsufficientArgumentsException.java index e4da53a91..61f2d3e83 100644 --- a/src/com/sk89q/worldedit/InsufficientArgumentsException.java +++ b/src/com/sk89q/worldedit/InsufficientArgumentsException.java @@ -1,5 +1,3 @@ -package com.sk89q.worldedit; - // $Id$ /* * WorldEdit @@ -19,6 +17,8 @@ * along with this program. If not, see . */ +package com.sk89q.worldedit; + /** * * @author sk89q diff --git a/src/com/sk89q/worldedit/NoSuchScriptException.java b/src/com/sk89q/worldedit/NoSuchScriptException.java new file mode 100644 index 000000000..b39a8eb8a --- /dev/null +++ b/src/com/sk89q/worldedit/NoSuchScriptException.java @@ -0,0 +1,28 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit; + +/** + * + * @author Albert + */ +public class NoSuchScriptException extends Exception { + +} diff --git a/src/com/sk89q/worldedit/UnknownItemException.java b/src/com/sk89q/worldedit/UnknownItemException.java index 5a493f0c6..d36ff844a 100644 --- a/src/com/sk89q/worldedit/UnknownItemException.java +++ b/src/com/sk89q/worldedit/UnknownItemException.java @@ -1,5 +1,3 @@ -package com.sk89q.worldedit; - // $Id$ /* * WorldEdit @@ -19,6 +17,8 @@ * along with this program. If not, see . */ +package com.sk89q.worldedit; + /** * Thrown when no item exist by the ID. *