diff --git a/src/main/java/cn/citycraft/Yum/file/commands/CommandDelete.java b/src/main/java/cn/citycraft/Yum/file/commands/CommandDelete.java index f66143b..6cc7bf0 100644 --- a/src/main/java/cn/citycraft/Yum/file/commands/CommandDelete.java +++ b/src/main/java/cn/citycraft/Yum/file/commands/CommandDelete.java @@ -18,11 +18,8 @@ import cn.citycraft.Yum.Yum; * @author 蒋天蓓 2015年8月12日下午2:04:05 */ public class CommandDelete extends BaseCommand { - Yum main; - public CommandDelete(final Yum main) { super("del"); - this.main = main; setMinimumArguments(1); setDescription("删除文件(服务器JAR为根目录)"); setPossibleArguments("<文件相对目录>"); diff --git a/src/main/java/cn/citycraft/Yum/file/commands/CommandDownLoad.java b/src/main/java/cn/citycraft/Yum/file/commands/CommandDownLoad.java index e20222e..8f9571d 100644 --- a/src/main/java/cn/citycraft/Yum/file/commands/CommandDownLoad.java +++ b/src/main/java/cn/citycraft/Yum/file/commands/CommandDownLoad.java @@ -45,8 +45,6 @@ public class CommandDownLoad extends BaseCommand { } else { file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr)); } - if (args.length == 1) { - dl.run(sender, urlstr, file); - } + dl.run(sender, urlstr, file); } } diff --git a/src/main/java/cn/citycraft/Yum/file/commands/CommandLs.java b/src/main/java/cn/citycraft/Yum/file/commands/CommandLs.java index 2da840c..ef15286 100644 --- a/src/main/java/cn/citycraft/Yum/file/commands/CommandLs.java +++ b/src/main/java/cn/citycraft/Yum/file/commands/CommandLs.java @@ -20,7 +20,7 @@ import cn.citycraft.Yum.Yum; public class CommandLs extends BaseCommand { public CommandLs(final Yum main) { - super(); + super("l"); setDescription("列出当前目录(服务器JAR为根目录)"); setPossibleArguments("<相对目录>"); } diff --git a/src/main/java/cn/citycraft/Yum/file/commands/CommandRename.java b/src/main/java/cn/citycraft/Yum/file/commands/CommandRename.java new file mode 100644 index 0000000..ee00fd4 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/file/commands/CommandRename.java @@ -0,0 +1,44 @@ +/** + * + */ +package cn.citycraft.Yum.file.commands; + +import java.io.File; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.Yum.Yum; + +/** + * 插件删除命令类 + * + * @author 蒋天蓓 2015年8月12日下午2:04:05 + */ +public class CommandRename extends BaseCommand { + public CommandRename(final Yum main) { + super("rn"); + setMinimumArguments(2); + setDescription("重命名文件(服务器JAR为根目录)"); + setPossibleArguments("<文件相对目录> <文件名称>"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final String fpath = args[0]; + final File file = new File(fpath); + if (!file.exists()) { + sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!"); + } else { + try { + final File newFile = new File(file.getParentFile(), args[1]); + file.renameTo(newFile); + sendMessage(sender, "§a文件 §e" + file.getAbsolutePath() + " §a重命名为 §d" + newFile.getAbsolutePath()); + } catch (final Exception e) { + sendMessage(sender, "§c文件 §e" + file.getAbsolutePath() + " §c重命名失败: " + e.getMessage()); + } + } + } +} diff --git a/src/main/java/cn/citycraft/Yum/file/commands/FileCommand.java b/src/main/java/cn/citycraft/Yum/file/commands/FileCommand.java index 16b833a..b483932 100644 --- a/src/main/java/cn/citycraft/Yum/file/commands/FileCommand.java +++ b/src/main/java/cn/citycraft/Yum/file/commands/FileCommand.java @@ -9,6 +9,7 @@ public class FileCommand { cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyFileCommandConsole", true)); cmdhandler.registerCommand(new CommandDownLoad(yum)); cmdhandler.registerCommand(new CommandDelete(yum)); + cmdhandler.registerCommand(new CommandRename(yum)); cmdhandler.registerCommand(new CommandRm(yum)); cmdhandler.registerCommand(new CommandLs(yum)); }