From b22921ffa69451b68da4e028c7b724adfbd1f0f8 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sat, 26 May 2012 11:06:31 -0700 Subject: [PATCH] Give a better error when a schematic being loaded doesn't exist Only require the schemaitc format to be provided once more schematic formats are added --- .../worldedit/commands/SchematicCommands.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/SchematicCommands.java b/src/main/java/com/sk89q/worldedit/commands/SchematicCommands.java index 1cbd658ce..90b94b032 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SchematicCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SchematicCommands.java @@ -77,6 +77,11 @@ public class SchematicCommands { File dir = we.getWorkingDirectoryFile(config.saveDir); File f = we.getSafeOpenFile(player, dir, fileName, "schematic", "schematic"); + if (!f.exists()) { + player.printError("Schemtic " + fileName + " does not exist!"); + return; + } + SchematicFormat format = formatName == null ? null : SchematicFormat.getFormat(formatName); if (format == null) { format = SchematicFormat.getFormat(f); @@ -112,11 +117,11 @@ public class SchematicCommands { @Command( aliases = { "save", "s" }, - usage = " ", + usage = "[format] ", desc = "Save a schematic into your clipboard", help = "Save a schematic into your clipboard\n" + "Format is a format from \"//schematic formats\"\n", - min = 2, + min = 1, max = 2 ) @CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save"}) // TODO: Remove 'clipboard' perm @@ -124,13 +129,23 @@ public class SchematicCommands { EditSession editSession) throws WorldEditException, CommandException { LocalConfiguration config = we.getConfiguration(); - SchematicFormat format = SchematicFormat.getFormat(args.getString(0)); - if (format == null) { - player.printError("Unknown schematic format: " + args.getString(0)); - return; + SchematicFormat format; + if (args.argsLength() == 1) { + if (SchematicFormat.getFormats().size() == 1) { + format = SchematicFormat.getFormats().iterator().next(); + } else { + player.printError("More than one schematic format is available. Please provide the desired format"); + return; + } + } else { + format = SchematicFormat.getFormat(args.getString(0)); + if (format == null) { + player.printError("Unknown schematic format: " + args.getString(0)); + return; + } } - String filename = args.getString(1); + String filename = args.getString(args.argsLength() - 1); File dir = we.getWorkingDirectoryFile(config.saveDir); File f = we.getSafeSaveFile(player, dir, filename, "schematic", "schematic");