From b715f8dfe8f52f0b2412fb91b78d5832c4ea248c Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 21 Dec 2015 14:59:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E5=91=BD=E4=BB=A4=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=91=BD=E4=BB=A4=E9=94=99=E8=AF=AF...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../Yum/file/commands/CommandDelete.java | 3 -- .../Yum/file/commands/CommandDownLoad.java | 4 +- .../Yum/file/commands/CommandLs.java | 2 +- .../Yum/file/commands/CommandRename.java | 44 +++++++++++++++++++ .../Yum/file/commands/FileCommand.java | 1 + 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 src/main/java/cn/citycraft/Yum/file/commands/CommandRename.java 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)); }