From 5d59dd764e74d53916b1ee103dc08e6816b873f6 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 27 Nov 2011 05:29:49 +0100 Subject: [PATCH] Changed getSafe*File to accept varargs instead of arrays. --- src/main/java/com/sk89q/worldedit/WorldEdit.java | 6 ++++-- .../com/sk89q/worldedit/commands/ClipboardCommands.java | 6 ++---- .../com/sk89q/worldedit/commands/ScriptingCommands.java | 6 ++---- .../com/sk89q/worldedit/scripting/CraftScriptContext.java | 6 +++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 54b9a44f0..9ae47dc09 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -646,7 +646,7 @@ public class WorldEdit { * @throws FilenameException */ public File getSafeSaveFile(LocalPlayer player, File dir, String filename, - String defaultExt, String[] extensions) + String defaultExt, String... extensions) throws FilenameException { return getSafeFile(player, dir, filename, defaultExt, extensions, true); } @@ -666,7 +666,7 @@ public class WorldEdit { * @throws FilenameException */ public File getSafeOpenFile(LocalPlayer player, File dir, String filename, - String defaultExt, String[] extensions) + String defaultExt, String... extensions) throws FilenameException { return getSafeFile(player, dir, filename, defaultExt, extensions, false); } @@ -686,6 +686,8 @@ public class WorldEdit { private File getSafeFile(LocalPlayer player, File dir, String filename, String defaultExt, String[] extensions, boolean isSave) throws FilenameException { + if (extensions.length == 1 && extensions[0] == null) extensions = null; + File f; if (filename.equals("#")) { diff --git a/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java b/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java index 72bfd6a77..b37875474 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java @@ -188,8 +188,7 @@ public class ClipboardCommands { String filename = args.getString(0); File dir = we.getWorkingDirectoryFile(config.saveDir); - File f = we.getSafeOpenFile(player, dir, filename, "schematic", - new String[] { "schematic" }); + File f = we.getSafeOpenFile(player, dir, filename, "schematic", "schematic"); try { String filePath = f.getCanonicalPath(); @@ -226,8 +225,7 @@ public class ClipboardCommands { String filename = args.getString(0); File dir = we.getWorkingDirectoryFile(config.saveDir); - File f = we.getSafeSaveFile(player, dir, filename, "schematic", - new String[] { "schematic" }); + File f = we.getSafeSaveFile(player, dir, filename, "schematic", "schematic"); if (!dir.exists()) { if (!dir.mkdir()) { diff --git a/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java b/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java index d5888c04c..a321912b4 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java @@ -57,8 +57,7 @@ public class ScriptingCommands { session.setLastScript(name); File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir); - File f = we.getSafeOpenFile(player, dir, name, "js", - new String[] { "js" }); + File f = we.getSafeOpenFile(player, dir, name, "js", "js"); we.runScript(player, f, scriptArgs); } @@ -91,8 +90,7 @@ public class ScriptingCommands { String[] scriptArgs = args.getSlice(0); File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir); - File f = we.getSafeOpenFile(player, dir, lastScript, "js", - new String[] { "js" }); + File f = we.getSafeOpenFile(player, dir, lastScript, "js", "js"); we.runScript(player, f, scriptArgs); } diff --git a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java index a4d98d603..a05165490 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java +++ b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java @@ -216,7 +216,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { @Deprecated public File getSafeFile(String folder, String filename) throws FilenameException { File dir = controller.getWorkingDirectoryFile(folder); - return controller.getSafeOpenFile(player, dir, filename, null, null); + return controller.getSafeOpenFile(player, dir, filename, null, (String[]) null); } /** @@ -236,7 +236,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { * @throws FilenameException */ public File getSafeOpenFile(String folder, String filename, - String defaultExt, String[] exts) + String defaultExt, String... exts) throws FilenameException { File dir = controller.getWorkingDirectoryFile(folder); return controller.getSafeOpenFile(player, dir, filename, defaultExt, exts); @@ -259,7 +259,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { * @throws FilenameException */ public File getSafeSaveFile(String folder, String filename, - String defaultExt, String[] exts) + String defaultExt, String... exts) throws FilenameException { File dir = controller.getWorkingDirectoryFile(folder); return controller.getSafeSaveFile(player, dir, filename, defaultExt, exts);