diff --git a/pom.xml b/pom.xml index 3095361..64786c9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft Yum - 1.9.5 + 1.9.5.1 Yum Minecraft 服务器插件管理系统 @@ -55,7 +55,7 @@ http://ci.citycraft.cn:8080 - &e添加yum info指令查看插件权限和注册命令... + &e添加fdel命令删除插件和数据文件... Debug UTF-8 diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandFullDelete.java b/src/main/java/cn/citycraft/Yum/commands/CommandFullDelete.java new file mode 100644 index 0000000..786e16d --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/commands/CommandFullDelete.java @@ -0,0 +1,47 @@ +/** + * + */ +package cn.citycraft.Yum.commands; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.Yum.Yum; +import cn.citycraft.Yum.api.YumAPI; + +/** + * 插件删除命令类 + * + * @author 蒋天蓓 2015年8月12日下午2:04:05 + */ +public class CommandFullDelete extends BaseCommand { + Yum main; + + public CommandFullDelete(final Yum main) { + super("fdel"); + this.main = main; + setMinimumArguments(1); + setDescription("删除插件以及数据文件夹"); + setPossibleArguments("<插件名称>"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final String pluginname = args[0]; + final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); + if (plugin != null) { + final String version = plugin.getDescription().getVersion(); + if (YumAPI.getPlugman().fullDeletePlugin(sender, plugin)) { + sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!"); + } else { + sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!"); + } + } else { + sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); + } + } +} diff --git a/src/main/java/cn/citycraft/Yum/commands/YumCommand.java b/src/main/java/cn/citycraft/Yum/commands/YumCommand.java index 398eef9..f539655 100644 --- a/src/main/java/cn/citycraft/Yum/commands/YumCommand.java +++ b/src/main/java/cn/citycraft/Yum/commands/YumCommand.java @@ -12,6 +12,7 @@ public class YumCommand { cmdhandler.registerCommand(new CommandUpdate(yum)); cmdhandler.registerCommand(new CommandUpdateAll(yum)); cmdhandler.registerCommand(new CommandDelete(yum)); + cmdhandler.registerCommand(new CommandFullDelete(yum)); cmdhandler.registerCommand(new CommandInfo(yum)); cmdhandler.registerCommand(new CommandRepo(yum)); cmdhandler.registerCommand(new CommandReload(yum)); diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java index 0066671..443c104 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java @@ -28,10 +28,10 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.UnknownDependencyException; -import org.bukkit.util.FileUtil; import com.google.common.base.Joiner; +import cn.citycraft.PluginHelper.utils.FileUtil; import cn.citycraft.PluginHelper.utils.StringUtil; /** @@ -128,6 +128,19 @@ public class PluginsManager { } } + /** + * 删除插件(包括数据) + * + * @param sender + * - 命令发送者 + * @param plugin + * - 插件 + * @return 是否成功 + */ + public boolean fullDeletePlugin(final CommandSender sender, final Plugin plugin) { + return unload(sender, plugin) && getPluginFile(plugin).delete() && FileUtil.deleteDir(sender, plugin.getDataFolder()); + } + /** * 获得格式化的插件名称 * @@ -617,7 +630,7 @@ public class PluginsManager { result = true; if (!unload(sender, name)) { sender.sendMessage("§6升级: §d开始安装 §b" + name + " §d插件!"); - FileUtil.copy(file, new File(Bukkit.getUpdateFolderFile().getParentFile(), File.separatorChar + file.getName())); + FileUtil.copyFile(file, new File(Bukkit.getUpdateFolderFile().getParentFile(), File.separatorChar + file.getName())); } else { sender.sendMessage("§6升级: §a开始升级 §b" + name + " §a插件!"); }