diff --git a/core/src/main/java/com/boydti/fawe/util/MainUtil.java b/core/src/main/java/com/boydti/fawe/util/MainUtil.java index 40b7baf4..899a6882 100644 --- a/core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -176,6 +176,11 @@ public class MainUtil { } } + public static File resolveRelative(File file) { + if (!file.exists()) return new File(relativize(file.getPath())); + return file; + } + public static String relativize(String path) { String[] split = path.split(Pattern.quote(File.separator)); StringBuilder out = new StringBuilder(); diff --git a/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index c5885d3b..f3ab2c1c 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -232,7 +232,7 @@ public class SchematicCommands extends MethodCommands { if (!filename.matches(".*\\.[\\w].*")) { filename += "." + format.getExtension(); } - f = new File(dir, filename); + f = MainUtil.resolveRelative(new File(dir, filename)); } if (f.getName().replaceAll("." + format.getExtension(), "").isEmpty()) { File directory = f.getParentFile(); @@ -251,10 +251,6 @@ public class SchematicCommands extends MethodCommands { } if (!f.exists() || !MainUtil.isInSubDirectory(working, f)) { player.printError("Schematic " + filename + " does not exist! (" + f.exists() + "|" + f + "|" + (!MainUtil.isInSubDirectory(working, f)) + ")"); - File absolute = f.getAbsoluteFile(); - player.printError("TEST0 " + absolute + " = " + absolute.exists()); - player.printError("TEST1 " + MainUtil.relativize(absolute.getPath()) + " = " + new File(MainUtil.relativize(absolute.getPath())).exists()); - player.printError("TEST1 " + MainUtil.relativize(f.getPath()) + " = " + new File(MainUtil.relativize(f.getPath())).exists()); return; } in = new FileInputStream(f); @@ -415,7 +411,8 @@ public class SchematicCommands extends MethodCommands { if (filename.equalsIgnoreCase("*")) { files.addAll(getFiles(session.getClipboard())); } else { - files.add(new File(dir, filename)); + File f = MainUtil.resolveRelative(new File(dir, filename)); + files.add(f); } if (files.isEmpty()) { BBC.SCHEMATIC_NONE.send(player); @@ -609,7 +606,7 @@ public class SchematicCommands extends MethodCommands { else if (hasShow) msg.text("&7[&3O&7]").command(showCmd + " " + args.getJoinedStrings(0) + " " + relFilePath).tooltip("Show"); msg.text(color + name); if (isDir) { - msg.command(list + " " + args.getJoinedStrings(0) + " " + relFilePath).tooltip("Load"); + msg.command(list + " " + relFilePath).tooltip("List"); } else { msg.command(loadSingle + " " + relFilePath).tooltip("Load"); } diff --git a/core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index eb6083b6..fb5dad02 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -24,6 +24,7 @@ import com.boydti.fawe.FaweAPI; import com.boydti.fawe.command.FaweParser; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Commands; +import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.DelegateConsumer; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FawePlayer; @@ -706,7 +707,7 @@ public class UtilityCommands extends MethodCommands { String dirFilter = File.separator; boolean listMine = false; - boolean listGlobal = false; + boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS; if (len > 0) { int max = len; if (MathMan.isInteger(args.getString(len - 1))) { @@ -733,7 +734,7 @@ public class UtilityCommands extends MethodCommands { if (arg.endsWith("/") || arg.endsWith(File.separator)) { arg = arg.replace("/", File.separator); String newDirFilter = dirFilter + arg; - boolean exists = new File(dir, newDirFilter).exists() || playerFolder && new File(dir, actor.getUniqueId() + newDirFilter).exists(); + boolean exists = new File(dir, newDirFilter).exists() || playerFolder && MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + newDirFilter)).exists(); if (!exists) { arg = arg.substring(0, arg.length() - File.separator.length()); if (arg.length() > 3 && arg.length() <= 16) { @@ -795,11 +796,11 @@ public class UtilityCommands extends MethodCommands { } if (playerFolder) { if (listMine) { - File playerDir = new File(dir, actor.getUniqueId() + dirFilter); + File playerDir = MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + dirFilter)); if (playerDir.exists()) allFiles(playerDir.listFiles(), false, forEachFile); } if (listGlobal) { - File rel = new File(dir, dirFilter); + File rel = MainUtil.resolveRelative(new File(dir, dirFilter)); forEachFile = new DelegateConsumer(forEachFile) { @Override public void accept(File f) { @@ -815,7 +816,7 @@ public class UtilityCommands extends MethodCommands { if (rel.exists()) allFiles(rel.listFiles(), false, forEachFile); } } else { - File rel = new File(dir, dirFilter); + File rel = MainUtil.resolveRelative(new File(dir, dirFilter)); if (rel.exists()) allFiles(rel.listFiles(), false, forEachFile); } if (!filters.isEmpty() && !toFilter.isEmpty()) {