From 5d444d20a1714dcf786b74905d87cbc84ce0f1e8 Mon Sep 17 00:00:00 2001 From: sk89q Date: Thu, 27 Jan 2011 01:51:34 -0800 Subject: [PATCH] Added LocalConfiguration.getWorkingDirectory(). --- src/com/sk89q/worldedit/CuboidClipboard.java | 4 ++-- src/com/sk89q/worldedit/LocalConfiguration.java | 10 ++++++++++ src/com/sk89q/worldedit/WorldEdit.java | 14 +++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/com/sk89q/worldedit/CuboidClipboard.java b/src/com/sk89q/worldedit/CuboidClipboard.java index fdea88da4..eb7354c68 100644 --- a/src/com/sk89q/worldedit/CuboidClipboard.java +++ b/src/com/sk89q/worldedit/CuboidClipboard.java @@ -260,7 +260,7 @@ public class CuboidClipboard { * @throws IOException * @throws DataException */ - public void saveSchematic(String path) throws IOException, DataException { + public void saveSchematic(File path) throws IOException, DataException { int width = getWidth(); int height = getHeight(); int length = getLength(); @@ -342,7 +342,7 @@ public class CuboidClipboard { * @throws DataException * @throws IOException */ - public static CuboidClipboard loadSchematic(String path) + public static CuboidClipboard loadSchematic(File path) throws DataException, IOException { FileInputStream stream = new FileInputStream(path); NBTInputStream nbtStream = new NBTInputStream(stream); diff --git a/src/com/sk89q/worldedit/LocalConfiguration.java b/src/com/sk89q/worldedit/LocalConfiguration.java index 12f3be51b..8049057d2 100644 --- a/src/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/com/sk89q/worldedit/LocalConfiguration.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit; +import java.io.File; import java.util.HashSet; import java.util.Set; @@ -61,4 +62,13 @@ public abstract class LocalConfiguration { * Loads the configuration. */ public abstract void load(); + + /** + * Get the working directory to work from. + * + * @return + */ + public File getWorkingDirectory() { + return new File("."); + } } diff --git a/src/com/sk89q/worldedit/WorldEdit.java b/src/com/sk89q/worldedit/WorldEdit.java index 453964e1a..587816f3d 100644 --- a/src/com/sk89q/worldedit/WorldEdit.java +++ b/src/com/sk89q/worldedit/WorldEdit.java @@ -981,8 +981,8 @@ public class WorldEdit { } else if (split[0].equalsIgnoreCase("//load")) { checkArgs(split, 1, 1, split[0]); String filename = split[1].replace("\0", "") + ".schematic"; - File dir = new File("schematics"); - File f = new File("schematics", filename); + File dir = new File(config.getWorkingDirectory(), "schematics"); + File f = new File(new File(config.getWorkingDirectory(), "schematics"), filename); if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) { player.printError("Valid characters: A-Z, a-z, 0-9, spaces, " @@ -997,7 +997,7 @@ public class WorldEdit { if (!filePath.substring(0, dirPath.length()).equals(dirPath)) { player.printError("Schematic could not read or it does not exist."); } else { - session.setClipboard(CuboidClipboard.loadSchematic(filePath)); + session.setClipboard(CuboidClipboard.loadSchematic(f)); logger.log(Level.INFO, player.getName() + " loaded " + filePath); player.print(filename + " loaded. Paste it with //paste"); } @@ -1020,8 +1020,8 @@ public class WorldEdit { return true; } - File dir = new File("schematics"); - File f = new File("schematics", filename); + File dir = new File(config.getWorkingDirectory(), "schematics"); + File f = new File(new File(config.getWorkingDirectory(), "schematics"), filename); if (!dir.exists()) { if (!dir.mkdir()) { @@ -1043,7 +1043,7 @@ public class WorldEdit { parent.mkdirs(); } - session.getClipboard().saveSchematic(filePath); + session.getClipboard().saveSchematic(f); logger.log(Level.INFO, player.getName() + " saved " + filePath); player.print(filename + " saved."); } @@ -2211,7 +2211,7 @@ public class WorldEdit { */ public void runScript(LocalPlayer player, String filename, String[] args) throws WorldEditException { - File dir = new File("craftscripts"); + File dir = new File(config.getWorkingDirectory(), "craftscripts"); File f = new File(dir, filename); if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$")) {