Added LocalConfiguration.getWorkingDirectory().

This commit is contained in:
sk89q 2011-01-27 01:51:34 -08:00
parent 68db2ebdd9
commit 5d444d20a1
3 changed files with 19 additions and 9 deletions

View File

@ -260,7 +260,7 @@ public class CuboidClipboard {
* @throws IOException * @throws IOException
* @throws DataException * @throws DataException
*/ */
public void saveSchematic(String path) throws IOException, DataException { public void saveSchematic(File path) throws IOException, DataException {
int width = getWidth(); int width = getWidth();
int height = getHeight(); int height = getHeight();
int length = getLength(); int length = getLength();
@ -342,7 +342,7 @@ public class CuboidClipboard {
* @throws DataException * @throws DataException
* @throws IOException * @throws IOException
*/ */
public static CuboidClipboard loadSchematic(String path) public static CuboidClipboard loadSchematic(File path)
throws DataException, IOException { throws DataException, IOException {
FileInputStream stream = new FileInputStream(path); FileInputStream stream = new FileInputStream(path);
NBTInputStream nbtStream = new NBTInputStream(stream); NBTInputStream nbtStream = new NBTInputStream(stream);

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import java.io.File;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -61,4 +62,13 @@ public abstract class LocalConfiguration {
* Loads the configuration. * Loads the configuration.
*/ */
public abstract void load(); public abstract void load();
/**
* Get the working directory to work from.
*
* @return
*/
public File getWorkingDirectory() {
return new File(".");
}
} }

View File

@ -981,8 +981,8 @@ public class WorldEdit {
} else if (split[0].equalsIgnoreCase("//load")) { } else if (split[0].equalsIgnoreCase("//load")) {
checkArgs(split, 1, 1, split[0]); checkArgs(split, 1, 1, split[0]);
String filename = split[1].replace("\0", "") + ".schematic"; String filename = split[1].replace("\0", "") + ".schematic";
File dir = new File("schematics"); File dir = new File(config.getWorkingDirectory(), "schematics");
File f = new File("schematics", filename); File f = new File(new File(config.getWorkingDirectory(), "schematics"), filename);
if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) { if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
player.printError("Valid characters: A-Z, a-z, 0-9, spaces, " 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)) { if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
player.printError("Schematic could not read or it does not exist."); player.printError("Schematic could not read or it does not exist.");
} else { } else {
session.setClipboard(CuboidClipboard.loadSchematic(filePath)); session.setClipboard(CuboidClipboard.loadSchematic(f));
logger.log(Level.INFO, player.getName() + " loaded " + filePath); logger.log(Level.INFO, player.getName() + " loaded " + filePath);
player.print(filename + " loaded. Paste it with //paste"); player.print(filename + " loaded. Paste it with //paste");
} }
@ -1020,8 +1020,8 @@ public class WorldEdit {
return true; return true;
} }
File dir = new File("schematics"); File dir = new File(config.getWorkingDirectory(), "schematics");
File f = new File("schematics", filename); File f = new File(new File(config.getWorkingDirectory(), "schematics"), filename);
if (!dir.exists()) { if (!dir.exists()) {
if (!dir.mkdir()) { if (!dir.mkdir()) {
@ -1043,7 +1043,7 @@ public class WorldEdit {
parent.mkdirs(); parent.mkdirs();
} }
session.getClipboard().saveSchematic(filePath); session.getClipboard().saveSchematic(f);
logger.log(Level.INFO, player.getName() + " saved " + filePath); logger.log(Level.INFO, player.getName() + " saved " + filePath);
player.print(filename + " saved."); player.print(filename + " saved.");
} }
@ -2211,7 +2211,7 @@ public class WorldEdit {
*/ */
public void runScript(LocalPlayer player, String filename, String[] args) public void runScript(LocalPlayer player, String filename, String[] args)
throws WorldEditException { throws WorldEditException {
File dir = new File("craftscripts"); File dir = new File(config.getWorkingDirectory(), "craftscripts");
File f = new File(dir, filename); File f = new File(dir, filename);
if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$")) { if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$")) {