去除离线缓存 修复版本更新模块...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2016-01-09 13:13:49 +08:00
parent d1fd6daa9a
commit 5f69c0abbd
28 changed files with 2056 additions and 2020 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId> <groupId>cn.citycraft</groupId>
<artifactId>Yum</artifactId> <artifactId>Yum</artifactId>
<version>1.9.6</version> <version>1.9.7</version>
<name>Yum</name> <name>Yum</name>
<description>Minecraft 服务器插件管理系统</description> <description>Minecraft 服务器插件管理系统</description>
<build> <build>
@ -55,7 +55,7 @@
</build> </build>
<properties> <properties>
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url> <jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<update.description>&amp;c修复没有Gson的服务端仓库管理出错的问题...</update.description> <update.description>&amp;c去除离线缓存 修复版本更新模块...</update.description>
<env.BUILD_NUMBER>Debug</env.BUILD_NUMBER> <env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

View File

@ -14,29 +14,24 @@ import cn.citycraft.Yum.file.commands.FileCommand;
/** /**
* MC插件仓库 * MC插件仓库
* *
* @author 蒋天蓓 2015年8月21日下午5:14:39 * @author
* @since 2015年8月21日下午5:14:39
*/ */
public class Yum extends JavaPlugin { public class Yum extends JavaPlugin {
public FileConfig config; public FileConfig config;
@Override @Override
public void onDisable() { public void onEnable() {
YumAPI.getRepo().cacheToJson(config); new YumAPI(this);
} new YumCommand(this);
new FileCommand(this);
new VersionChecker(this);
YumAPI.updaterepo();
}
@Override @Override
public void onEnable() { public void onLoad() {
new YumAPI(this); config = new FileConfig(this);
new YumCommand(this); }
new FileCommand(this);
YumAPI.getRepo().jsonToCache(config);
YumAPI.updaterepo();
new VersionChecker(this);
}
@Override
public void onLoad() {
config = new FileConfig(this);
}
} }

View File

@ -20,316 +20,318 @@ import cn.citycraft.Yum.manager.RepositoryManager;
/** /**
* Yum管理中心 * Yum管理中心
* *
* @author 蒋天蓓 * @author
* 2015年9月1日上午10:59:47 * @since 2015年9月1日上午10:59:47
*/ */
public class YumAPI { public class YumAPI {
private static DownloadManager download; private static DownloadManager download;
private static Plugin main; private static Plugin main;
private static PluginsManager plugman; private static PluginsManager plugman;
private static RepositoryManager repo; private static RepositoryManager repo;
/** /**
* 初始化Yum管理中心 * 初始化Yum管理中心
* *
* @param plugin * @param plugin
* 插件实体 * 插件实体
*/ */
public YumAPI(final Plugin plugin) { public YumAPI(final Plugin plugin) {
YumAPI.main = plugin; YumAPI.main = plugin;
plugman = new PluginsManager(main); plugman = new PluginsManager(main);
download = new DownloadManager(main); download = new DownloadManager(main);
repo = new RepositoryManager(main); repo = new RepositoryManager(main);
} }
/** /**
* 删除插件 * 删除插件
* *
* @param plugin * @param plugin
* 插件实体 * 插件实体
*/ */
public static void delete(final Plugin plugin) { public static void delete(final Plugin plugin) {
plugman.deletePlugin(plugin); plugman.deletePlugin(plugin);
} }
/** /**
* 获得下载管理器 * 获得下载管理器
* *
* @return {@link DownloadManager} * @return {@link DownloadManager}
*/ */
public static DownloadManager getDownload() { public static DownloadManager getDownload() {
return download; return download;
} }
/** /**
* 获得插件管理器 * 获得插件管理器
* *
* @return {@link PluginsManager} * @return {@link PluginsManager}
*/ */
public static PluginsManager getPlugman() { public static PluginsManager getPlugman() {
return plugman; return plugman;
} }
/** /**
* 获得仓库管理器 * 获得仓库管理器
* *
* @return {@link RepositoryManager} * @return {@link RepositoryManager}
*/ */
public static RepositoryManager getRepo() { public static RepositoryManager getRepo() {
return repo; return repo;
} }
/** /**
* 安装新插件 * 安装新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param pluginname * @param pluginname
* 插件名称 * 插件名称
* @param version * @param version
* 插件版本 * 插件版本
* @return 是否安装成功 * @return 是否安装成功
*/ */
public static boolean install(final CommandSender sender, final String pluginname, final String url) { public static boolean install(final CommandSender sender, final String pluginname, final String url) {
final File pluginFile = new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar"); final File pluginFile = new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar");
if (download.run(sender, url, pluginFile)) { if (download.run(sender, url, pluginFile)) {
return plugman.load(sender, pluginFile); return plugman.load(sender, pluginFile);
} }
return false; return false;
} }
/** /**
* 安装新插件 * 安装新插件
* *
* @param pluginname * @param pluginname
* 插件名称 * 插件名称
* @param version * @param version
* 插件版本 * 插件版本
* @return 是否安装成功 * @return 是否安装成功
*/ */
public static boolean install(final String pluginname, final String url) { public static boolean install(final String pluginname, final String url) {
return install(null, pluginname, url); return install(null, pluginname, url);
} }
/** /**
* 安装新插件 * 安装新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param pluginname * @param pluginname
* 插件名称 * 插件名称
* @return 是否安装成功 * @return 是否安装成功
*/ */
public static boolean installfromyum(final CommandSender sender, final String pluginname) { public static boolean installfromyum(final CommandSender sender, final String pluginname) {
return installfromyum(sender, pluginname, null); return installfromyum(sender, pluginname, null);
} }
/** /**
* 安装新插件 * 安装新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param pluginname * @param pluginname
* 插件名称 * 插件名称
* @param version * @param version
* 插件版本 * 插件版本
* @return 是否安装成功 * @return 是否安装成功
*/ */
public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) { public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) {
final PluginInfo pi = repo.getPlugin(pluginname); final PluginInfo pi = repo.getPlugin(pluginname);
if (pi != null) { if (pi != null) {
return install(sender, pi.name, pi.getUrl(sender, version)); return install(sender, pi.name, pi.getUrl(sender, version));
} }
return false; return false;
} }
/** /**
* 载入插件 * 载入插件
* *
* @param pluginname * @param pluginname
* 插件名称 * 插件名称
*/ */
public static void load(final File pluginFile) { public static void load(final File pluginFile) {
plugman.load(pluginFile); plugman.load(pluginFile);
} }
/** /**
* 载入插件 * 载入插件
* *
* @param pluginname * @param pluginname
* 插件名称 * 插件名称
*/ */
public static void load(final String pluginname) { public static void load(final String pluginname) {
plugman.load(pluginname); plugman.load(pluginname);
} }
/** /**
* 重载插件 * 重载插件
* *
* @param plugin * @param plugin
* 插件实体 * 插件实体
*/ */
public static void reload(final Plugin plugin) { public static void reload(final Plugin plugin) {
plugman.reload(plugin); plugman.reload(plugin);
} }
/** /**
* 卸载插件 * 卸载插件
* *
* @param plugin * @param plugin
* 插件实体 * 插件实体
*/ */
public static void unload(final Plugin plugin) { public static void unload(final Plugin plugin) {
plugman.unload(plugin); plugman.unload(plugin);
} }
/** /**
* 更新插件 * 更新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param plugin * @param plugin
* 插件实体 * 插件实体
* @param url * @param url
* 新插件的下载地址 * 新插件的下载地址
* @return 是否更新成功 * @return 是否更新成功
*/ */
public static boolean update(final CommandSender sender, final Plugin plugin, final URL url) { public static boolean update(final CommandSender sender, final Plugin plugin, final URL url) {
if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹"); sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!"); sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
return true; return true;
} }
return false; return false;
} }
/** /**
* 更新插件 * 更新插件
* *
* @param plugin * @param plugin
* 插件实体 * 插件实体
* @param url * @param url
* 新插件的下载地址 * 新插件的下载地址
* @return 是否更新成功 * @return 是否更新成功
*/ */
public static boolean update(final Plugin plugin, final URL url) { public static boolean update(final Plugin plugin, final URL url) {
return update(null, plugin, url); return update(null, plugin, url);
} }
/** /**
* 更新支持Yum的插件 * 更新支持Yum的插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
*/ */
public static void updateall(final CommandSender sender) { public static void updateall(final CommandSender sender) {
final List<Plugin> ulist = new ArrayList<>(); final List<Plugin> ulist = new ArrayList<>();
try { try {
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) { for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
ulist.add(updateplugin.getValue()); ulist.add(updateplugin.getValue());
} }
UpdatePlugin.clearList(); UpdatePlugin.clearList();
} catch (final Exception | Error e) { } catch (final Exception | Error e) {
try { try {
final Map<Plugin, String> updatelist = UpdatePlugin.getList(); final Map<Plugin, String> updatelist = UpdatePlugin.getList();
ulist.addAll(updatelist.keySet()); ulist.addAll(updatelist.keySet());
UpdatePlugin.getList().clear(); UpdatePlugin.getList().clear();
} catch (final Exception | Error e2) { } catch (final Exception | Error e2) {
sender.sendMessage("§4错误: §c无法检索全体更新列表!"); sender.sendMessage("§4错误: §c无法检索全体更新列表!");
sender.sendMessage("§4异常: §c" + e2.getMessage()); sender.sendMessage("§4异常: §c" + e2.getMessage());
} }
} }
if (ulist.size() > 0) { if (ulist.size() > 0) {
for (final Plugin updateplugin : ulist) { for (final Plugin updateplugin : ulist) {
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!"); sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
updatefromyum(sender, updateplugin, null, true); updatefromyum(sender, updateplugin, null, true);
} }
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹"); sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!"); sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
} else { } else {
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!"); sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
} }
} }
/** /**
* 更新插件 * 更新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param plugin * @param plugin
* 插件实体 * 插件实体
* @return 是否更新成功 * @return 是否更新成功
*/ */
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) { public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) {
return updatefromyum(sender, plugin, null); return updatefromyum(sender, plugin, null);
} }
/** /**
* 从Yum内部更新插件 * 从Yum内部更新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param plugin * @param plugin
* 插件实体 * 插件实体
* @param version * @param version
* 插件版本(null则自动获取) * 插件版本(null则自动获取)
* @return * @return
*/ */
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) { public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
return updatefromyum(sender, plugin, version, false); return updatefromyum(sender, plugin, version, false);
} }
/** /**
* 从Yum内部更新插件 * 从Yum内部更新插件
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param plugin * @param plugin
* 插件实体 * 插件实体
* @param version * @param version
* 插件版本(null则自动获取) * 插件版本(null则自动获取)
* @param oneKeyUpdate * @param oneKeyUpdate
* 是否一键更新 * 是否一键更新
* @return * @return
*/ */
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) { public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) {
final PluginInfo pi = repo.getPlugin(plugin.getName()); final PluginInfo pi = repo.getPlugin(plugin.getName());
if (pi != null) { if (pi != null) {
if (download.run(sender, pi.getUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) { final File pFile = new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName());
if (!oneKeyUpdate) { if (download.run(sender, pi.getUrl(sender, version), pFile)) {
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
}
return true;
}
} else {
sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
}
return false;
}
/** if (!oneKeyUpdate) {
* 更新Yum源数据 sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
*/ sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
public static void updaterepo() { }
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() { return true;
@Override }
public void run() { } else {
repo.updateRepositories(Bukkit.getConsoleSender()); sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
} }
}); return false;
} }
/** /**
* @param sender * 更新Yum源数据
* 命令发送者 */
* @param plugin public static void updaterepo() {
* 插件实体 main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
*/ @Override
public static void upgrade(final CommandSender sender, final Plugin plugin) { public void run() {
plugman.upgrade(sender, plugin); repo.updateRepositories(Bukkit.getConsoleSender());
} }
});
}
/**
* @param sender
* 命令发送者
* @param plugin
* 插件实体
*/
public static void upgrade(final CommandSender sender, final Plugin plugin) {
plugman.upgrade(sender, plugin);
}
} }

View File

@ -16,32 +16,33 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandDelete extends BaseCommand { public class CommandDelete extends BaseCommand {
Yum main; Yum main;
public CommandDelete(final Yum main) { public CommandDelete(final Yum main) {
super("del"); super("del");
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("删除插件"); setDescription("删除插件");
setPossibleArguments("<插件名称>"); setPossibleArguments("<插件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
final String version = plugin.getDescription().getVersion(); final String version = plugin.getDescription().getVersion();
if (YumAPI.getPlugman().deletePlugin(sender, plugin)) { if (YumAPI.getPlugman().deletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!"); sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
} else { } else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!"); sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
} }
} else { } else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
} }
} }
} }

View File

@ -16,32 +16,33 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandFullDelete extends BaseCommand { public class CommandFullDelete extends BaseCommand {
Yum main; Yum main;
public CommandFullDelete(final Yum main) { public CommandFullDelete(final Yum main) {
super("fdel"); super("fdel");
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("删除插件以及数据文件夹"); setDescription("删除插件以及数据文件夹");
setPossibleArguments("<插件名称>"); setPossibleArguments("<插件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
final String version = plugin.getDescription().getVersion(); final String version = plugin.getDescription().getVersion();
if (YumAPI.getPlugman().fullDeletePlugin(sender, plugin)) { if (YumAPI.getPlugman().fullDeletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!"); sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
} else { } else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!"); sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
} }
} else { } else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
} }
} }
} }

View File

@ -23,59 +23,60 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandInfo extends BaseCommand { public class CommandInfo extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandInfo(final Yum main) { public CommandInfo(final Yum main) {
super(); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("查看插件详情"); setDescription("查看插件详情");
setPossibleArguments("<插件名称>"); setPossibleArguments("<插件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = main.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = main.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
final PluginDescriptionFile desc = plugin.getDescription(); final PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage("§6插件名称: §3" + plugin.getName()); sender.sendMessage("§6插件名称: §3" + plugin.getName());
sender.sendMessage("§6插件版本: §3" + desc.getVersion()); sender.sendMessage("§6插件版本: §3" + desc.getVersion());
sender.sendMessage("§6插件作者: §3" + StringUtils.join(desc.getAuthors(), " ")); sender.sendMessage("§6插件作者: §3" + StringUtils.join(desc.getAuthors(), " "));
sender.sendMessage("§6插件描述: §3" + (desc.getDescription() == null ? "" : desc.getDescription())); sender.sendMessage("§6插件描述: §3" + (desc.getDescription() == null ? "" : desc.getDescription()));
sender.sendMessage("§6插件依赖: §3" + (desc.getDepend().isEmpty() ? "" : "")); sender.sendMessage("§6插件依赖: §3" + (desc.getDepend().isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a"); StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().isEmpty() ? "" : "")); sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a"); StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
final Map<String, Map<String, Object>> clist = desc.getCommands(); final Map<String, Map<String, Object>> clist = desc.getCommands();
if (clist != null) { if (clist != null) {
sender.sendMessage("§6插件注册命令: §3" + (clist.isEmpty() ? "" : "")); sender.sendMessage("§6插件注册命令: §3" + (clist.isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, clist.keySet(), "§6 - §a"); StringUtil.sendStringArray(sender, clist.keySet(), "§6 - §a");
} }
final List<Permission> plist = desc.getPermissions(); final List<Permission> plist = desc.getPermissions();
if (plist != null) { if (plist != null) {
sender.sendMessage("§6插件注册权限: " + (plist.isEmpty() ? "" : "")); sender.sendMessage("§6插件注册权限: " + (plist.isEmpty() ? "" : ""));
for (final Permission perm : plist) { for (final Permission perm : plist) {
sender.sendMessage("§6 - §a" + perm.getName() + "§6 - §e" + (perm.getDescription().isEmpty() ? "无描述" : perm.getDescription())); sender.sendMessage("§6 - §a" + perm.getName() + "§6 - §e" + (perm.getDescription().isEmpty() ? "无描述" : perm.getDescription()));
} }
} }
sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath()); sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath());
} else { } else {
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
} }
} }
@Override @Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) { if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) {
return StringUtil.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
} }
return null; return null;
} }
} }

View File

@ -20,47 +20,48 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件安装命令类 * 插件安装命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandInstall extends BaseCommand { public class CommandInstall extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandInstall(final Yum main) { public CommandInstall(final Yum main) {
super("i"); super("i");
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("安装插件"); setDescription("安装插件");
setPossibleArguments("<插件名称>"); setPossibleArguments("<插件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) { if (plugin == null) {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override @Override
public void run() { public void run() {
if (args.length < 2) { if (args.length < 2) {
YumAPI.installfromyum(sender, pluginname); YumAPI.installfromyum(sender, pluginname);
} else { } else {
YumAPI.installfromyum(sender, pluginname, args[1]); YumAPI.installfromyum(sender, pluginname, args[1]);
} }
} }
}); });
} else { } else {
sender.sendMessage("§c插件" + pluginname + "已安装在服务器 需要更新请使用yum update " + pluginname + "!"); sender.sendMessage("§c插件" + pluginname + "已安装在服务器 需要更新请使用yum update " + pluginname + "!");
} }
} }
@Override @Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args[0].equalsIgnoreCase("install")) { if (args[0].equalsIgnoreCase("install")) {
return StringUtil.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>());
} }
return null; return null;
} }
} }

View File

@ -16,25 +16,26 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件查看命令类 * 插件查看命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandList extends BaseCommand { public class CommandList extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandList(final Yum main) { public CommandList(final Yum main) {
super("l"); super("l");
this.main = main; this.main = main;
setDescription("列出已安装插件列表"); setDescription("列出已安装插件列表");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: "); sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
sender.sendMessage("§6- " + YumAPI.getPlugman().getFormattedName(plugin, true)); sender.sendMessage("§6- " + YumAPI.getPlugman().getFormattedName(plugin, true));
} }
}; };
} }

View File

@ -16,30 +16,31 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandLoad extends BaseCommand { public class CommandLoad extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandLoad(final Yum main) { public CommandLoad(final Yum main) {
super(); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("载入插件"); setDescription("载入插件");
setPossibleArguments("<插件名称>"); setPossibleArguments("<插件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) { if (plugin == null) {
YumAPI.getPlugman().load(sender, pluginname); YumAPI.getPlugman().load(sender, pluginname);
} else { } else {
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!"); sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
} }
}; };
} }

View File

@ -16,34 +16,35 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandReload extends BaseCommand { public class CommandReload extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandReload(final Yum main) { public CommandReload(final Yum main) {
super(); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("重载插件"); setDescription("重载插件");
setPossibleArguments("<插件名称|all|*>"); setPossibleArguments("<插件名称|all|*>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) { if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
YumAPI.getPlugman().reloadAll(sender); YumAPI.getPlugman().reloadAll(sender);
return; return;
} }
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
YumAPI.getPlugman().reload(sender, plugin); YumAPI.getPlugman().reload(sender, plugin);
} else { } else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
} }
}; };
} }

View File

@ -20,89 +20,90 @@ import cn.citycraft.Yum.manager.RepoSerialization.Repositories;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandRepo extends BaseCommand { public class CommandRepo extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandRepo(final Yum main) { public CommandRepo(final Yum main) {
super("r"); super("r");
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("插件源命令"); setDescription("插件源命令");
setPossibleArguments("<add|del|all|clean|list> <仓库名称>"); setPossibleArguments("<add|del|all|clean|list> <仓库名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() { main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override @Override
public void run() { public void run() {
final String cmd = args[0]; final String cmd = args[0];
switch (cmd) { switch (cmd) {
case "add": case "add":
if (args.length == 2) { if (args.length == 2) {
if (YumAPI.getRepo().addRepositories(sender, args[1])) { if (YumAPI.getRepo().addRepositories(sender, args[1])) {
final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name; final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name;
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!"); sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
} else { } else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
} }
} else { } else {
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!"); sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
} }
break; break;
case "del": case "del":
if (args.length == 2) { if (args.length == 2) {
final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]); final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]);
if (delrepo != null) { if (delrepo != null) {
YumAPI.getRepo().delRepositories(sender, args[1]); YumAPI.getRepo().delRepositories(sender, args[1]);
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!"); sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
} else { } else {
sender.sendMessage("§6仓库: §c源地址未找到!"); sender.sendMessage("§6仓库: §c源地址未找到!");
} }
} else { } else {
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!"); sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
} }
break; break;
case "delall": case "delall":
YumAPI.getRepo().getRepoCache().getRepos().clear(); YumAPI.getRepo().getRepoCache().getRepos().clear();
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!"); sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
break; break;
case "list": case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo()); StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
break; break;
case "all": case "all":
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 "); sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo()); StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
break; break;
case "clean": case "clean":
YumAPI.getRepo().clean(); YumAPI.getRepo().clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
break; break;
case "update": case "update":
YumAPI.getRepo().updateRepositories(sender); YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!"); sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break; break;
} }
} }
}); });
} }
@Override @Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args[0].equalsIgnoreCase("repo")) { if (args[0].equalsIgnoreCase("repo")) {
if (args.length == 2) { if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList<String>());
} }
if (args.length == 3 && (args[1] == "add" || args[1] == "del")) { if (args.length == 3 && (args[1] == "add" || args[1] == "del")) {
return StringUtil.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>());
} }
} }
return null; return null;
} }
} }

View File

@ -16,30 +16,31 @@ import cn.citycraft.Yum.api.YumAPI;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandUnload extends BaseCommand { public class CommandUnload extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandUnload(final Yum main) { public CommandUnload(final Yum main) {
super(); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("卸载插件"); setDescription("卸载插件");
setPossibleArguments("<插件名称>"); setPossibleArguments("<插件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
YumAPI.getPlugman().unload(sender, plugin); YumAPI.getPlugman().unload(sender, plugin);
} else { } else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
} }
}; };
} }

View File

@ -14,37 +14,49 @@ import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI; import cn.citycraft.Yum.api.YumAPI;
/** /**
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandUpdate extends BaseCommand { public class CommandUpdate extends BaseCommand {
Yum main; Yum main;
public CommandUpdate(final Yum main) { public CommandUpdate(final Yum main) {
super("u"); super("u");
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(0);
setDescription("更新插件"); setDescription("更新插件或缓存");
setPossibleArguments("<插件名称> [插件版本]"); setPossibleArguments("[插件名称] [插件版本]");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; switch (args.length) {
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); case 0:
sender.sendMessage("§a开始更新插件: " + pluginname); YumAPI.getRepo().updateRepositories(sender);
if (plugin != null) { sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { break;
@Override case 1:
public void run() { case 2:
if (args.length < 2) { final String pluginname = args[0];
YumAPI.updatefromyum(sender, plugin); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
} else { sender.sendMessage("§a开始更新插件: " + pluginname);
YumAPI.updatefromyum(sender, plugin, args[1]); if (plugin != null) {
} Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
} @Override
}); public void run() {
} else { if (args.length < 2) {
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!"); YumAPI.updatefromyum(sender, plugin);
} } else {
}; YumAPI.updatefromyum(sender, plugin, args[1]);
}
}
});
} else {
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
}
break;
default:
sendHelp(sender, label);
}
}
} }

View File

@ -13,25 +13,26 @@ import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI; import cn.citycraft.Yum.api.YumAPI;
/** /**
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandUpdateAll extends BaseCommand { public class CommandUpdateAll extends BaseCommand {
Yum main; Yum main;
public CommandUpdateAll(final Yum main) { public CommandUpdateAll(final Yum main) {
super("ua"); super("ua");
this.main = main; this.main = main;
setDescription("更新所有可更新插件"); setDescription("更新所有可更新插件");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
sender.sendMessage("§d开始更新服务器可更新插件"); sender.sendMessage("§d开始更新服务器可更新插件");
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override @Override
public void run() { public void run() {
YumAPI.updateall(sender); YumAPI.updateall(sender);
} }
}); });
}; };
} }

View File

@ -14,39 +14,40 @@ import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI; import cn.citycraft.Yum.api.YumAPI;
/** /**
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandUpgrade extends BaseCommand { public class CommandUpgrade extends BaseCommand {
Yum main; Yum main;
/** /**
* @param name * @param name
*/ */
public CommandUpgrade(final Yum main) { public CommandUpgrade(final Yum main) {
super("ug"); super("ug");
this.main = main; this.main = main;
setDescription("升级插件"); setDescription("升级插件");
setPossibleArguments("[插件名称]"); setPossibleArguments("[插件名称]");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override @Override
public void run() { public void run() {
if (args.length == 0) { if (args.length == 0) {
YumAPI.getPlugman().upgrade(sender); YumAPI.getPlugman().upgrade(sender);
} else { } else {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始升级插件: " + pluginname); sender.sendMessage("§a开始升级插件: " + pluginname);
if (plugin != null) { if (plugin != null) {
YumAPI.upgrade(sender, plugin); YumAPI.upgrade(sender, plugin);
} else { } else {
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!"); sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
} }
} }
} }
}); });
}; };
} }

View File

@ -3,21 +3,27 @@ package cn.citycraft.Yum.commands;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand; import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import cn.citycraft.Yum.Yum; import cn.citycraft.Yum.Yum;
/**
* Yum命令基类
*
* @since 2016年1月9日 上午10:02:24
* @author
*/
public class YumCommand { public class YumCommand {
public YumCommand(final Yum yum) { public YumCommand(final Yum yum) {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum"); final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum");
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false)); cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false));
cmdhandler.registerCommand(new CommandList(yum)); cmdhandler.registerCommand(new CommandList(yum));
cmdhandler.registerCommand(new CommandInstall(yum)); cmdhandler.registerCommand(new CommandInstall(yum));
cmdhandler.registerCommand(new CommandUpdate(yum)); cmdhandler.registerCommand(new CommandUpdate(yum));
cmdhandler.registerCommand(new CommandUpdateAll(yum)); cmdhandler.registerCommand(new CommandUpdateAll(yum));
cmdhandler.registerCommand(new CommandDelete(yum)); cmdhandler.registerCommand(new CommandDelete(yum));
cmdhandler.registerCommand(new CommandFullDelete(yum)); cmdhandler.registerCommand(new CommandFullDelete(yum));
cmdhandler.registerCommand(new CommandInfo(yum)); cmdhandler.registerCommand(new CommandInfo(yum));
cmdhandler.registerCommand(new CommandRepo(yum)); cmdhandler.registerCommand(new CommandRepo(yum));
cmdhandler.registerCommand(new CommandReload(yum)); cmdhandler.registerCommand(new CommandReload(yum));
cmdhandler.registerCommand(new CommandLoad(yum)); cmdhandler.registerCommand(new CommandLoad(yum));
cmdhandler.registerCommand(new CommandUnload(yum)); cmdhandler.registerCommand(new CommandUnload(yum));
cmdhandler.registerCommand(new CommandUpgrade(yum)); cmdhandler.registerCommand(new CommandUpgrade(yum));
} }
} }

View File

@ -15,32 +15,33 @@ import cn.citycraft.Yum.Yum;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandDelete extends BaseCommand { public class CommandDelete extends BaseCommand {
public CommandDelete(final Yum main) { public CommandDelete(final Yum main) {
super("del"); super("del");
setMinimumArguments(1); setMinimumArguments(1);
setDescription("删除文件(服务器JAR为根目录)"); setDescription("删除文件(服务器JAR为根目录)");
setPossibleArguments("<文件相对目录>"); setPossibleArguments("<文件相对目录>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String fpath = args[0]; final String fpath = args[0];
final File file = new File(fpath); final File file = new File(fpath);
if (!file.exists()) { if (!file.exists()) {
sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!"); sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!");
} else { } else {
if (file.isDirectory()) { if (file.isDirectory()) {
sendMessage(sender, "§e" + file.getAbsolutePath() + " §c是一个目录 请使用file rm!"); sendMessage(sender, "§e" + file.getAbsolutePath() + " §c是一个目录 请使用file rm!");
return; return;
} }
try { try {
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " " + (file.delete() ? "§a删除成功!" : "§c删除失败!")); sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " " + (file.delete() ? "§a删除成功!" : "§c删除失败!"));
} catch (final Exception e) { } catch (final Exception e) {
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " 删除失败: " + e.getMessage()); sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " 删除失败: " + e.getMessage());
} }
} }
} }
} }

View File

@ -18,33 +18,34 @@ import cn.citycraft.Yum.manager.DownloadManager;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandDownLoad extends BaseCommand { public class CommandDownLoad extends BaseCommand {
Yum main; Yum main;
DownloadManager dl; DownloadManager dl;
public CommandDownLoad(final Yum main) { public CommandDownLoad(final Yum main) {
super("d"); super("d");
this.main = main; this.main = main;
dl = YumAPI.getDownload(); dl = YumAPI.getDownload();
setMinimumArguments(1); setMinimumArguments(1);
setDescription("下载文件(默认保存到服务器更新文件夹)"); setDescription("下载文件(默认保存到服务器更新文件夹)");
setPossibleArguments("<下载地址> [保存文件路径]"); setPossibleArguments("<下载地址> [保存文件路径]");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
String urlstr = args[0]; String urlstr = args[0];
if (!urlstr.startsWith("http")) { if (!urlstr.startsWith("http")) {
urlstr = "http://" + urlstr; urlstr = "http://" + urlstr;
} }
File file = null; File file = null;
if (args.length == 2) { if (args.length == 2) {
file = new File(args[1]); file = new File(args[1]);
} else { } else {
file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr)); file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr));
} }
dl.run(sender, urlstr, file); dl.run(sender, urlstr, file);
} }
} }

View File

@ -15,41 +15,42 @@ import cn.citycraft.Yum.Yum;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandLs extends BaseCommand { public class CommandLs extends BaseCommand {
public CommandLs(final Yum main) { public CommandLs(final Yum main) {
super("l"); super("l");
setDescription("列出当前目录(服务器JAR为根目录)"); setDescription("列出当前目录(服务器JAR为根目录)");
setPossibleArguments("<相对目录>"); setPossibleArguments("<相对目录>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
File dir = new File("."); File dir = new File(".");
if (args.length == 1) { if (args.length == 1) {
dir = new File(args[0]); dir = new File(args[0]);
} }
if (!dir.isDirectory()) { if (!dir.isDirectory()) {
sendMessage(sender, "§6路径: §e " + dir.getAbsolutePath() + " §c不是一个目录!"); sendMessage(sender, "§6路径: §e " + dir.getAbsolutePath() + " §c不是一个目录!");
return; return;
} }
final StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
for (final File file : dir.listFiles()) { for (final File file : dir.listFiles()) {
if (file.isDirectory()) { if (file.isDirectory()) {
sb.append("§b"); sb.append("§b");
} else { } else {
sb.append("§a"); sb.append("§a");
} }
sb.append(file.getName() + " "); sb.append(file.getName() + " ");
} }
final String filelist = sb.toString(); final String filelist = sb.toString();
if (filelist.isEmpty()) { if (filelist.isEmpty()) {
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §c下没有文件或文件夹!"); sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §c下没有文件或文件夹!");
} else { } else {
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §a存在如下文件!"); sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §a存在如下文件!");
sendMessage(sender, sb.toString()); sendMessage(sender, sb.toString());
} }
} }
} }

View File

@ -15,30 +15,31 @@ import cn.citycraft.Yum.Yum;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandRename extends BaseCommand { public class CommandRename extends BaseCommand {
public CommandRename(final Yum main) { public CommandRename(final Yum main) {
super("rn"); super("rn");
setMinimumArguments(2); setMinimumArguments(2);
setDescription("重命名文件(服务器JAR为根目录)"); setDescription("重命名文件(服务器JAR为根目录)");
setPossibleArguments("<文件相对目录> <文件名称>"); setPossibleArguments("<文件相对目录> <文件名称>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String fpath = args[0]; final String fpath = args[0];
final File file = new File(fpath); final File file = new File(fpath);
if (!file.exists()) { if (!file.exists()) {
sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!"); sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!");
} else { } else {
try { try {
final File newFile = new File(file.getParentFile(), args[1]); final File newFile = new File(file.getParentFile(), args[1]);
file.renameTo(newFile); file.renameTo(newFile);
sendMessage(sender, "§a文件 §e" + file.getAbsolutePath() + " §a重命名为 §d" + newFile.getAbsolutePath()); sendMessage(sender, "§a文件 §e" + file.getAbsolutePath() + " §a重命名为 §d" + newFile.getAbsolutePath());
} catch (final Exception e) { } catch (final Exception e) {
sendMessage(sender, "§c文件 §e" + file.getAbsolutePath() + " §c重命名失败: " + e.getMessage()); sendMessage(sender, "§c文件 §e" + file.getAbsolutePath() + " §c重命名失败: " + e.getMessage());
} }
} }
} }
} }

View File

@ -16,42 +16,43 @@ import cn.citycraft.Yum.Yum;
/** /**
* 插件删除命令类 * 插件删除命令类
* *
* @author 蒋天蓓 2015年8月12日下午2:04:05 * @author
* @since 2015年8月12日下午2:04:05
*/ */
public class CommandRm extends BaseCommand { public class CommandRm extends BaseCommand {
Yum plugin; Yum plugin;
public CommandRm(final Yum main) { public CommandRm(final Yum main) {
super(); super();
plugin = main; plugin = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("删除文件夹(服务器JAR为根目录)"); setDescription("删除文件夹(服务器JAR为根目录)");
setPossibleArguments("<文件相对目录>"); setPossibleArguments("<文件相对目录>");
} }
@Override @Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String fpath = args[0]; final String fpath = args[0];
final File file = new File(fpath); final File file = new File(fpath);
if (!file.exists()) { if (!file.exists()) {
sendMessage(sender, "§c目录 " + file.getAbsolutePath() + " 不存在!"); sendMessage(sender, "§c目录 " + file.getAbsolutePath() + " 不存在!");
} else { } else {
if (!file.isDirectory()) { if (!file.isDirectory()) {
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c是一个文件 请使用file delete!"); sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c是一个文件 请使用file delete!");
return; return;
} }
for (final String name : plugin.config.getStringList("blacklist")) { for (final String name : plugin.config.getStringList("blacklist")) {
if (file.getAbsolutePath().toLowerCase().endsWith(name)) { if (file.getAbsolutePath().toLowerCase().endsWith(name)) {
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c不允许被删除!"); sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c不允许被删除!");
return; return;
} }
} }
if (file.listFiles().length != 0 && !(args.length > 1 && args[1].equalsIgnoreCase("-rf"))) { if (file.listFiles().length != 0 && !(args.length > 1 && args[1].equalsIgnoreCase("-rf"))) {
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " §c不为空!"); sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " §c不为空!");
sendMessage(sender, "§c请使用 §a/file rm " + fpath + " -rf §c强行删除!"); sendMessage(sender, "§c请使用 §a/file rm " + fpath + " -rf §c强行删除!");
return; return;
} }
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " " + (FileUtil.deleteDir(sender, file) ? "§a删除成功!" : "§c删除失败!")); sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " " + (FileUtil.deleteDir(sender, file) ? "§a删除成功!" : "§c删除失败!"));
} }
} }
} }

View File

@ -3,14 +3,20 @@ package cn.citycraft.Yum.file.commands;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand; import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import cn.citycraft.Yum.Yum; import cn.citycraft.Yum.Yum;
/**
* File命令基类
*
* @since 2016年1月9日 上午10:02:39
* @author
*/
public class FileCommand { public class FileCommand {
public FileCommand(final Yum yum) { public FileCommand(final Yum yum) {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "file"); final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "file");
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyFileCommandConsole", true)); cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyFileCommandConsole", true));
cmdhandler.registerCommand(new CommandDownLoad(yum)); cmdhandler.registerCommand(new CommandDownLoad(yum));
cmdhandler.registerCommand(new CommandDelete(yum)); cmdhandler.registerCommand(new CommandDelete(yum));
cmdhandler.registerCommand(new CommandRename(yum)); cmdhandler.registerCommand(new CommandRename(yum));
cmdhandler.registerCommand(new CommandRm(yum)); cmdhandler.registerCommand(new CommandRm(yum));
cmdhandler.registerCommand(new CommandLs(yum)); cmdhandler.registerCommand(new CommandLs(yum));
} }
} }

View File

@ -9,199 +9,207 @@ import java.net.URL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
/** /**
* 下载管理类 * 下载管理类
* *
* @author 蒋天蓓 * @author
* 2015年8月21日下午6:08:09 * @since 2015年8月21日下午6:08:09
*/ */
public class DownloadManager { public class DownloadManager {
Plugin plugin; Plugin plugin;
public DownloadManager(final Plugin main) { public DownloadManager(final Plugin main) {
this.plugin = main; this.plugin = main;
} }
/** /**
* 从地址获得文件名称 * 从地址获得文件名称
* *
* @param url * @param url
* - 地址 * - 地址
* @return 文件名称 * @return 文件名称
*/ */
public String getFileName(final String url) { public String getFileName(final String url) {
final int end = url.lastIndexOf('/'); final int end = url.lastIndexOf('/');
return url.substring(end + 1); return url.substring(end + 1);
} }
/** /**
* 从地址获得文件名称 * 从地址获得文件名称
* *
* @param url * @param url
* - 地址 * - 地址
* @return 文件名称 * @return 文件名称
*/ */
public String getFileName(final URL url) { public String getFileName(final URL url) {
return getFileName(url.getFile()); return getFileName(url.getFile());
} }
/** /**
* 从网络下载文件 * 从网络下载文件
* *
* @param sender * @param sender
* - 命令发送者 * - 命令发送者
* @param urlstring * @param urlstring
* - 下载地址 * - 下载地址
* @return 是否成功 * @return 是否成功
*/ */
public boolean run(final CommandSender sender, final String urlstring) { public boolean run(final CommandSender sender, final String urlstring) {
return run(sender, urlstring, new File("plugins", getFileName(urlstring))); return run(sender, urlstring, new File("plugins", getFileName(urlstring)));
} }
/** /**
* 从网络下载文件 * 从网络下载文件
* *
* @param sender * @param sender
* - 命令发送者 * - 命令发送者
* @param urlstring * @param urlstring
* - 下载地址 * - 下载地址
* @param file * @param file
* - 保存文件 * - 保存文件
* @return 是否成功 * @return 是否成功
*/ */
public boolean run(final CommandSender sender, final String urlstring, final File file) { public boolean run(final CommandSender sender, final String urlstring, final File file) {
try { try {
final URL url = new URL(urlstring); final URL url = new URL(urlstring);
return run(sender, url, file); return run(sender, url, file);
} catch (final MalformedURLException e) { } catch (final MalformedURLException e) {
sender.sendMessage("§4错误: §c无法识别的URL地址..."); sender.sendMessage("§4错误: §c无法识别的URL地址...");
sender.sendMessage("§4地址: §c" + urlstring); sender.sendMessage("§4地址: §c" + urlstring);
return false; return false;
} }
} }
/** /**
* 从网络下载文件 * 从网络下载文件
* *
* @param sender * @param sender
* - 命令发送者 * - 命令发送者
* @param url * @param url
* - 下载地址 * - 下载地址
* @param file * @param file
* - 保存文件 * - 保存文件
* @return 是否成功 * @return 是否成功
*/ */
public boolean run(CommandSender sender, final URL url, final File file) { public boolean run(CommandSender sender, final URL url, final File file) {
BufferedInputStream in = null; BufferedInputStream in = null;
FileOutputStream fout = null; FileOutputStream fout = null;
if (sender == null) { if (sender == null) {
sender = Bukkit.getConsoleSender(); sender = Bukkit.getConsoleSender();
} }
try { try {
sender.sendMessage("§6开始下载: §3" + getFileName(url)); sender.sendMessage("§6开始下载: §3" + getFileName(url));
sender.sendMessage("§6下载地址: §3" + url.toString()); sender.sendMessage("§6下载地址: §3" + url.toString());
final int fileLength = url.openConnection().getContentLength(); final int fileLength = url.openConnection().getContentLength();
if (fileLength < 0) { if (fileLength < 0) {
sender.sendMessage("§6下载: §c文件 " + file.getName() + " 获取长度错误(可能是网络问题)!"); sender.sendMessage("§6下载: §c文件 " + file.getName() + " 获取长度错误(可能是网络问题)!");
sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!"); sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!");
return false; return false;
} }
sender.sendMessage("§6文件长度: §3" + fileLength); sender.sendMessage("§6文件长度: §3" + fileLength);
in = new BufferedInputStream(url.openStream()); in = new BufferedInputStream(url.openStream());
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
sender.sendMessage("§6创建新目录: §d" + file.getParentFile().getAbsolutePath()); sender.sendMessage("§6创建新目录: §d" + file.getParentFile().getAbsolutePath());
} }
if (file.exists()) { if (file.exists()) {
file.delete(); file.delete();
} }
file.createNewFile(); file.createNewFile();
sender.sendMessage("§6创建新文件: §d" + file.getAbsolutePath()); sender.sendMessage("§6创建新文件: §d" + file.getAbsolutePath());
fout = new FileOutputStream(file); fout = new FileOutputStream(file);
final byte[] data = new byte[1024]; final byte[] data = new byte[1024];
long downloaded = 0L; long downloaded = 0L;
int count; int count;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
while ((count = in.read(data)) != -1) { while ((count = in.read(data)) != -1) {
downloaded += count; downloaded += count;
fout.write(data, 0, count); fout.write(data, 0, count);
final int percent = (int) (downloaded * 100L / fileLength); final int percent = (int) (downloaded * 100L / fileLength);
if (percent % 10 == 0) { if (percent % 10 == 0) {
if (System.currentTimeMillis() - time > 500) { if (System.currentTimeMillis() - time > 500) {
sender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent)); sender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent));
time = System.currentTimeMillis(); time = System.currentTimeMillis();
} }
} }
} }
sender.sendMessage("§6文件: §a " + file.getName() + " 下载完成!"); String pVer = null;
return true; try {
} catch (final Exception ex) { final PluginDescriptionFile desc = plugin.getPluginLoader().getPluginDescription(file);
sender.sendMessage("§6异常: §c" + ex.getMessage()); pVer = desc.getVersion();
sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!"); } catch (final Exception e) {
return false; pVer = "";
} finally { }
try { sender.sendMessage("§6" + (pVer.isEmpty() ? "文件" : "插件") + ": §b" + file.getName() + (pVer.isEmpty() ? "" : " 版本 §e" + pVer) + " §a下载完成!");
if (in != null) { return true;
in.close(); } catch (final Exception ex) {
} sender.sendMessage("§6异常: §c" + ex.getMessage());
if (fout != null) { sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!");
fout.close(); return false;
} } finally {
} catch (final Exception ex) { try {
} if (in != null) {
} in.close();
} }
if (fout != null) {
fout.close();
}
} catch (final Exception ex) {
}
}
}
/** /**
* 从网络下载文件 * 从网络下载文件
* *
* @param urlstring * @param urlstring
* - 下载地址 * - 下载地址
* @return 是否成功 * @return 是否成功
*/ */
public boolean run(final String urlstring) { public boolean run(final String urlstring) {
return run(null, urlstring); return run(null, urlstring);
} }
/** /**
* 从网络下载文件 * 从网络下载文件
* *
* @param urlstring * @param urlstring
* - 下载地址 * - 下载地址
* @param file * @param file
* - 保存文件 * - 保存文件
* @return 是否成功 * @return 是否成功
*/ */
public boolean run(final String urlstring, final File file) { public boolean run(final String urlstring, final File file) {
return run(null, urlstring, file); return run(null, urlstring, file);
} }
/** /**
* 从网络下载文件 * 从网络下载文件
* *
* @param url * @param url
* - 下载地址 * - 下载地址
* @param file * @param file
* - 保存文件 * - 保存文件
* @return 是否成功 * @return 是否成功
*/ */
public boolean run(final URL url, final File file) { public boolean run(final URL url, final File file) {
return run(null, url, file); return run(null, url, file);
} }
private String getPer(final int per) { private String getPer(final int per) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
if (per > i) { if (per > i) {
sb.append("=="); sb.append("==");
} else if (per == i) { } else if (per == i) {
sb.append("> "); sb.append("> ");
} else { } else {
sb.append(" "); sb.append(" ");
} }
} }
return sb.toString(); return sb.toString();
} }
} }

View File

@ -10,113 +10,113 @@ import cn.citycraft.Yum.manager.RepoSerialization.TagInfo;
import cn.citycraft.Yum.manager.RepoSerialization.URLType; import cn.citycraft.Yum.manager.RepoSerialization.URLType;
public class PluginInfo { public class PluginInfo {
public static final String NMSVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; public static final String NMSVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
public String branch; public String branch;
public String name; public String name;
public Plugin plugin; public Plugin plugin;
public String pom; public String pom;
public URLType type; public URLType type;
public String repo; public String repo;
public String url; public String url;
/** /**
* 获得下载直链 * 获得下载直链
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param version * @param version
* 版本 * 版本
* @return 下载直链 * @return 下载直链
*/ */
public String getDirectUrl() { public String getDirectUrl() {
return url; return url;
} }
/** /**
* 获得下载直链 * 获得下载直链
* *
* @param sender * @param sender
* 命令发送者 * 命令发送者
* @param version * @param version
* 版本 * 版本
* @return 下载直链 * @return 下载直链
*/ */
public String getDirectUrl(final String version) { public String getDirectUrl(final String version) {
return url.replace("[version]", version); return url.replace("[version]", version);
} }
/** /**
* 获得文件名称 * 获得文件名称
* *
* @return 文件名称 * @return 文件名称
*/ */
public String getFileName() { public String getFileName() {
return getFileName(plugin.version); return getFileName(plugin.version);
} }
/** /**
* 获得文件名称 * 获得文件名称
* *
* @param version * @param version
* 插件版本 * 插件版本
* @return 文件名称 * @return 文件名称
*/ */
public String getFileName(final String version) { public String getFileName(final String version) {
return String.format("%1$s-%2$s.jar", plugin.artifactId, version); return String.format("%1$s-%2$s.jar", plugin.artifactId, version);
} }
/** /**
* 获取Maven仓库指定插件的下载地址 * 获取Maven仓库指定插件的下载地址
* *
* @param sender * @param sender
* - 命令发送者 * - 命令发送者
* @param version * @param version
* - 需要更新的版本 * - 需要更新的版本
* @return 更新地址 * @return 更新地址
*/ */
public String getMavenUrl(final String ver) { public String getMavenUrl(final String ver) {
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar",
plugin.groupId.replace(".", "/"), plugin.groupId.replace(".", "/"),
plugin.artifactId, plugin.artifactId,
(ver == null || ver.isEmpty()) ? plugin.version : ver); (ver == null || ver.isEmpty()) ? plugin.version : ver);
} }
public String getUrl(final CommandSender sender, final String version) { public String getUrl(final CommandSender sender, final String version) {
String ver = version; String ver = version;
if (ver == null) { if (ver == null) {
if (plugin.tags != null) { if (plugin.tags != null) {
PluginHelperLogger.getLogger().debug("发现存在TAG标签 开始检索: " + NMSVersion); PluginHelperLogger.getLogger().debug("发现存在TAG标签 开始检索: " + NMSVersion);
for (final TagInfo tagInfo : plugin.tags) { for (final TagInfo tagInfo : plugin.tags) {
if (tagInfo.tag.equalsIgnoreCase(NMSVersion)) { if (tagInfo.tag.equalsIgnoreCase(NMSVersion)) {
sender.sendMessage("§6版本: §b从Tag标签中获取 §e" + NMSVersion + " §b的最新版本..."); sender.sendMessage("§6版本: §b从Tag标签中获取 §e" + NMSVersion + " §b的最新版本...");
ver = tagInfo.version; ver = tagInfo.version;
if (tagInfo.type == URLType.DirectUrl) { if (tagInfo.type == URLType.DirectUrl) {
return tagInfo.url; return tagInfo.url;
} }
break; break;
} }
} }
} else if (pom != null && !pom.isEmpty()) { } else if (pom != null && !pom.isEmpty()) {
pom = pom.replace("[name]", name).replace("[branch]", branch); pom = pom.replace("[name]", name).replace("[branch]", branch);
sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本..."); sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本...");
ver = IOUtil.getXMLTag(pom, "version", plugin.version); ver = IOUtil.getXMLTag(pom, "version", null);
if (ver != null) { if (ver != null) {
sender.sendMessage("§6版本: §a成功获取到最新版本 §e" + ver + " §a..."); sender.sendMessage("§6版本: §a成功获取到最新版本 §e" + ver + " §a...");
} }
} }
} }
if (ver == null) { if (ver == null) {
ver = plugin.version; ver = plugin.version;
sender.sendMessage("§6版本: §a使用缓存的版本 §e" + ver + " §a..."); sender.sendMessage("§6版本: §d使用缓存的版本 §e" + ver + " §a...");
} }
switch (type) { switch (type) {
case DirectUrl: case DirectUrl:
return getDirectUrl(ver); return getDirectUrl(ver);
case Maven: case Maven:
return getMavenUrl(ver); return getMavenUrl(ver);
default: default:
return null; return null;
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -6,72 +6,77 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import cn.citycraft.PluginHelper.PluginHelperLogger;
import cn.citycraft.PluginHelper.jsonresult.JsonHandle; import cn.citycraft.PluginHelper.jsonresult.JsonHandle;
import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.PluginHelper.utils.IOUtil;
import cn.citycraft.Yum.manager.RepoSerialization.Repositories; import cn.citycraft.Yum.manager.RepoSerialization.Repositories;
public class RepoCache { public class RepoCache {
Map<String, PluginInfo> plugins = new HashMap<String, PluginInfo>(); PluginHelperLogger logger = PluginHelperLogger.getLogger();
Map<String, Repositories> repos = new HashMap<String, Repositories>(); Map<String, PluginInfo> plugins = new HashMap<String, PluginInfo>();
Map<String, Repositories> repos = new HashMap<String, Repositories>();
public static RepoCache fromJson(final String json) { public static RepoCache fromJson(final String json) {
return JsonHandle.fromJson(json, RepoCache.class); return JsonHandle.fromJson(json, RepoCache.class);
} }
public void addPlugins(final String name, final PluginInfo info) { public void addPlugins(final String name, final PluginInfo info) {
plugins.put(name, info); plugins.put(name, info);
} }
public Repositories addRepo(final String repo) { public Repositories addRepo(final String repo) {
if (repos.containsKey(repo) || repo.isEmpty()) { if (repos.containsKey(repo) || repo.isEmpty()) {
return null; logger.debug("源地址为空或已存在 " + repo);
} return null;
final Repositories reposes = getRepo(repo); }
if (reposes == null) { final Repositories reposes = getRepo(repo);
return null; if (reposes == null) {
} return null;
repos.put(repo, reposes); }
return reposes; repos.put(repo, reposes);
} return reposes;
}
public List<String> getAllRepoInfo() { public List<String> getAllRepoInfo() {
final List<String> repoinfo = new ArrayList<String>(); final List<String> repoinfo = new ArrayList<String>();
for (final Entry<String, Repositories> repo : repos.entrySet()) { for (final Entry<String, Repositories> repo : repos.entrySet()) {
repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey())); repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey()));
} }
return repoinfo; return repoinfo;
} }
public Map<String, PluginInfo> getPlugins() { public Map<String, PluginInfo> getPlugins() {
return plugins; return plugins;
} }
public Repositories getRepo(final String repo) { public Repositories getRepo(final String repo) {
final String json = IOUtil.getData(repo); final String json = IOUtil.getData(repo);
if (json == null || json.isEmpty()) { if (json == null || json.isEmpty()) {
return null; logger.debug("源地址获取数据为空 " + repo);
} return null;
final Repositories reposes = JsonHandle.fromJson(json, Repositories.class); }
if (reposes == null || reposes.repos.isEmpty()) { final Repositories reposes = JsonHandle.fromJson(json, Repositories.class);
return null; if (reposes == null || reposes.repos.isEmpty()) {
} logger.debug("源地址解析Json为空 " + repo);
return reposes; return null;
} }
return reposes;
}
public Map<String, Repositories> getRepos() { public Map<String, Repositories> getRepos() {
return repos; return repos;
} }
public boolean removeRepo(final String repo) { public boolean removeRepo(final String repo) {
if (repo.isEmpty() || !repos.containsKey(repo)) { if (repo.isEmpty() || !repos.containsKey(repo)) {
return false; return false;
} }
repos.remove(repo); repos.remove(repo);
return true; return true;
} }
@Override @Override
public String toString() { public String toString() {
return JsonHandle.toJson(this); return JsonHandle.toJson(this);
} }
} }

View File

@ -9,51 +9,51 @@ import java.util.List;
/** /**
* 源仓库序列化类 * 源仓库序列化类
* *
* @author 蒋天蓓 * @author
* 2015年8月31日下午7:41:53 * @since 2015年8月31日下午7:41:53
*/ */
public class RepoSerialization { public class RepoSerialization {
public class PackageInfo { public class PackageInfo {
public String name; public String name;
public List<Plugin> plugins = new ArrayList<>(); public List<Plugin> plugins = new ArrayList<>();
public String pom; public String pom;
public String url; public String url;
public URLType type; public URLType type;
} }
public class Plugin { public class Plugin {
public String artifactId; public String artifactId;
public String branch; public String branch;
public String description; public String description;
public String groupId; public String groupId;
public String name; public String name;
public String url; public String url;
public String pom; public String pom;
public List<TagInfo> tags; public List<TagInfo> tags;
public String version; public String version;
public URLType type; public URLType type;
} }
public class Repositories { public class Repositories {
public String name; public String name;
public List<Repository> repos; public List<Repository> repos;
} }
public class Repository { public class Repository {
public String id; public String id;
public URLType type; public URLType type;
public String url; public String url;
} }
public class TagInfo { public class TagInfo {
public String tag; public String tag;
public String version; public String version;
public URLType type; public URLType type;
public String url; public String url;
} }
public enum URLType { public enum URLType {
Maven, Maven,
DirectUrl; DirectUrl;
} }
} }

View File

@ -11,9 +11,8 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.PluginHelperLogger;
import cn.citycraft.PluginHelper.jsonresult.JsonHandle; import cn.citycraft.PluginHelper.jsonresult.JsonHandle;
import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.PluginHelper.utils.IOUtil;
import cn.citycraft.PluginHelper.utils.StringUtil; import cn.citycraft.PluginHelper.utils.StringUtil;
@ -27,218 +26,204 @@ import cn.citycraft.Yum.manager.RepoSerialization.URLType;
/** /**
* 仓库管理类 * 仓库管理类
* *
* @author 蒋天蓓 * @author
* @since 2016年1月9日 上午10:02:57
*/ */
public class RepositoryManager { public class RepositoryManager {
org.bukkit.plugin.Plugin main; PluginHelperLogger logger = PluginHelperLogger.getLogger();
RepoCache repocache; org.bukkit.plugin.Plugin main;
RepoCache repocache;
public RepositoryManager(final org.bukkit.plugin.Plugin plugin) { public RepositoryManager(final org.bukkit.plugin.Plugin plugin) {
this.main = plugin; this.main = plugin;
repocache = new RepoCache(); repocache = new RepoCache();
} }
public boolean addPackage(final CommandSender sender, final String urlstring) { public boolean addPackage(final CommandSender sender, final String urlstring) {
final String json = IOUtil.getData(urlstring); final String json = IOUtil.getData(urlstring);
if (json == null || json.isEmpty()) { if (json == null || json.isEmpty()) {
return false; return false;
} }
final PackageInfo pkg = jsonToPackage(json); final PackageInfo pkg = jsonToPackage(json);
if (pkg == null) { if (pkg == null) {
return false; return false;
} }
updatePackage(sender, pkg); updatePackage(sender, pkg);
return true; return true;
} }
public boolean addRepositories(final CommandSender sender, final String urlstring) { public boolean addRepositories(final CommandSender sender, final String urlstring) {
final String url = handerRepoUrl(urlstring); final String url = handerRepoUrl(urlstring);
final Repositories repo = repocache.addRepo(url); final Repositories repo = repocache.addRepo(url);
if (repo == null) { if (repo == null) {
return false; return false;
} }
return updateRepositories(sender, repo); return updateRepositories(sender, repo);
} }
public void cacheToJson(final FileConfig config) { public void clean() {
config.set("reposcache", repocache.toString()); repocache.getPlugins().clear();
config.save(); }
}
public void clean() { public boolean delRepositories(final CommandSender sender, final String urlstring) {
repocache.getPlugins().clear(); return repocache.removeRepo(handerRepoUrl(urlstring));
} }
public boolean delRepositories(final CommandSender sender, final String urlstring) { public List<PluginInfo> getAllPlugin() {
return repocache.removeRepo(handerRepoUrl(urlstring)); final List<PluginInfo> li = new ArrayList<PluginInfo>();
} for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
li.add(plugin.getValue());
}
return li;
}
public List<PluginInfo> getAllPlugin() { public List<String> getAllPluginName() {
final List<PluginInfo> li = new ArrayList<PluginInfo>(); final List<String> li = new ArrayList<String>();
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
li.add(plugin.getValue()); li.add(plugin.getValue().name);
} }
return li; return li;
} }
public List<String> getAllPluginName() { public List<String> getAllPluginsInfo() {
final List<String> li = new ArrayList<String>(); final List<String> li = new ArrayList<String>();
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { li.add("§d仓库名称 §a插件名称 §e插件描述");
li.add(plugin.getValue().name); for (final Entry<String, PluginInfo> pi : repocache.getPlugins().entrySet()) {
} final Plugin plugin = pi.getValue().plugin;
return li; li.add(String.format("§d%s §a%s §6- §e%s", pi.getValue().repo, pi.getValue().name, plugin.description));
} if (plugin.tags != null) {
li.add(" §b┗Tags §c标签 §a版本 §e类型");
final List<TagInfo> taglist = plugin.tags;
for (int i = 0; i < taglist.size(); i++) {
final TagInfo tag = taglist.get(i);
li.add(" §b" + (i == taglist.size() - 1 ? "" : "") + String.format("§c%s §a%s §e%s", tag.tag, tag.version, tag.type != null ? tag.type : URLType.Maven));
}
}
}
return li;
}
public List<String> getAllPluginsInfo() { public PluginInfo getPlugin(final String name) {
final List<String> li = new ArrayList<String>(); for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
li.add("§d仓库名称 §a插件名称 §e插件描述"); if (plugin.getValue().name.equalsIgnoreCase(name)) {
for (final Entry<String, PluginInfo> pi : repocache.getPlugins().entrySet()) { return plugin.getValue();
final Plugin plugin = pi.getValue().plugin; }
li.add(String.format("§d%s §a%s §6- §e%s", pi.getValue().repo, pi.getValue().name, plugin.description)); }
if (plugin.tags != null) { return null;
li.add(" §b┗Tags §c标签 §a版本 §e类型"); }
final List<TagInfo> taglist = plugin.tags;
for (int i = 0; i < taglist.size(); i++) {
final TagInfo tag = taglist.get(i);
li.add(" §b" + (i == taglist.size() - 1 ? "" : "") + String.format("§c%s §a%s §e%s", tag.tag, tag.version, tag.type != null ? tag.type : URLType.Maven));
}
}
}
return li;
}
public PluginInfo getPlugin(final String name) { public List<PluginInfo> getPluginInfo(final String name) {
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { final List<PluginInfo> li = new ArrayList<PluginInfo>();
if (plugin.getValue().name.equalsIgnoreCase(name)) { for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
return plugin.getValue(); if (plugin.getValue().name.equalsIgnoreCase(name)) {
} li.add(plugin.getValue());
} }
return null; }
} return li;
}
public List<PluginInfo> getPluginInfo(final String name) { public PluginInfo getPluginInfo(final String groupId, final String artifactId) {
final List<PluginInfo> li = new ArrayList<PluginInfo>(); return repocache.getPlugins().get(groupId + "." + artifactId);
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { }
if (plugin.getValue().name.equalsIgnoreCase(name)) {
li.add(plugin.getValue());
}
}
return li;
}
public PluginInfo getPluginInfo(final String groupId, final String artifactId) { public Map<String, PluginInfo> getPlugins() {
return repocache.getPlugins().get(groupId + "." + artifactId); return repocache.getPlugins();
} }
public Map<String, PluginInfo> getPlugins() { public RepoCache getRepoCache() {
return repocache.getPlugins(); return repocache;
} }
public RepoCache getRepoCache() { public Repositories getRepoCache(final String urlstring) {
return repocache; return repocache.repos.get(handerRepoUrl(urlstring));
} }
public Repositories getRepoCache(final String urlstring) { public Map<String, Repositories> getRepos() {
return repocache.repos.get(handerRepoUrl(urlstring)); return repocache.getRepos();
} }
public Map<String, Repositories> getRepos() { public boolean getRepositories(final CommandSender sender, final String urlstring) {
return repocache.getRepos(); final int urllength = urlstring.length();
} final String url = urlstring.substring(0, urlstring.endsWith("/") ? urllength - 1 : urllength);
handerRepoUrl(url);
final Repositories repo = repocache.addRepo(urlstring);
if (repo == null) {
return false;
}
return updateRepositories(sender, repo);
}
public boolean getRepositories(final CommandSender sender, final String urlstring) { public PackageInfo jsonToPackage(final String json) {
final int urllength = urlstring.length(); try {
final String url = urlstring.substring(0, urlstring.endsWith("/") ? urllength - 1 : urllength); return JsonHandle.fromJson(json, PackageInfo.class);
handerRepoUrl(url); } catch (final Exception e) {
final Repositories repo = repocache.addRepo(urlstring); return null;
if (repo == null) { }
return false; }
}
return updateRepositories(sender, repo);
}
public boolean jsonToCache(final FileConfiguration config) { public Repositories jsonToRepositories(final String json) {
try { return JsonHandle.fromJson(json, Repositories.class);
final String reposcache = config.getString("reposcache"); }
if (reposcache != null && !reposcache.isEmpty()) {
repocache = RepoCache.fromJson(reposcache);
return true;
}
} catch (final Exception e) {
}
return false;
}
public PackageInfo jsonToPackage(final String json) { public void updatePackage(final CommandSender sender, final PackageInfo pkg) {
try { for (final Plugin plugin : pkg.plugins) {
return JsonHandle.fromJson(json, PackageInfo.class); final PluginInfo pi = new PluginInfo();
} catch (final Exception e) { pi.name = StringUtil.getNotNull(plugin.name, plugin.artifactId);
return null; pi.branch = StringUtil.getNotNull(plugin.branch, "master");
} pi.pom = StringUtil.getNotNull(plugin.pom, pkg.pom);
} pi.url = StringUtil.getNotNull(plugin.url, pkg.url);
pi.type = plugin.type != null ? plugin.type : pkg.type;
pi.type = pi.type != null ? pi.type : URLType.Maven;
pi.plugin = plugin;
pi.repo = pkg.name;
repocache.getPlugins().put(plugin.groupId + "." + plugin.artifactId, pi);
}
sender.sendMessage("§6仓库: §e" + pkg.name + " §a更新成功!");
}
public Repositories jsonToRepositories(final String json) { public boolean updateRepositories(final CommandSender sender) {
return JsonHandle.fromJson(json, Repositories.class); repocache.getPlugins().clear();
} if (repocache.getRepos().isEmpty()) {
repocache.addRepo("https://coding.net/u/502647092/p/YumData/git/raw/master/yumcenter/repo.info");
}
final Iterator<Entry<String, Repositories>> keys = repocache.getRepos().entrySet().iterator();
while (keys.hasNext()) {
final Entry<String, Repositories> string = keys.next();
final Repositories repo = repocache.getRepo(string.getKey());
if (updateRepositories(sender, repo)) {
sender.sendMessage("§6源: §e" + repo.name + " §a更新成功!");
} else {
sender.sendMessage("§6源: §e" + string.getKey() + " §c未找到任何仓库信息 已删除!");
keys.remove();
}
}
return true;
}
public void updatePackage(final CommandSender sender, final PackageInfo pkg) { public boolean updateRepositories(CommandSender sender, final Repositories repocenter) {
for (final Plugin plugin : pkg.plugins) { if (sender == null) {
final PluginInfo pi = new PluginInfo(); sender = Bukkit.getConsoleSender();
pi.name = StringUtil.getNotNull(plugin.name, plugin.artifactId); }
pi.branch = StringUtil.getNotNull(plugin.branch, "master"); if (repocenter == null || repocenter.repos.isEmpty()) {
pi.pom = StringUtil.getNotNull(plugin.pom, pkg.pom); logger.debug("源地址为Null或源列表为空!");
pi.url = StringUtil.getNotNull(plugin.url, pkg.url); return false;
pi.type = plugin.type != null ? plugin.type : pkg.type; }
pi.type = pi.type != null ? pi.type : URLType.Maven; for (final Repository repo : repocenter.repos) {
pi.plugin = plugin; addPackage(sender, repo.url);
pi.repo = pkg.name; }
repocache.getPlugins().put(plugin.groupId + "." + plugin.artifactId, pi); return true;
} }
sender.sendMessage("§6仓库: §e" + pkg.name + " §a更新成功!");
}
public boolean updateRepositories(final CommandSender sender) { private String handerRepoUrl(String url) {
repocache.getPlugins().clear(); final int urllength = url.length();
if (repocache.getRepos().isEmpty()) { url = url.substring(0, url.endsWith("/") ? urllength - 1 : urllength);
repocache.addRepo("https://coding.net/u/502647092/p/YumData/git/raw/master/yumcenter/repo.info"); if (!url.startsWith("http://")) {
} url = "http://" + url;
final Iterator<Entry<String, Repositories>> keys = repocache.getRepos().entrySet().iterator(); }
while (keys.hasNext()) { if (!url.endsWith("repo.info")) {
final Entry<String, Repositories> string = keys.next(); url = url + "/repo.info";
final Repositories repo = repocache.getRepo(string.getKey()); }
if (updateRepositories(sender, repo)) { return url;
sender.sendMessage("§6源: §e" + repo.name + " §a更新成功!"); }
} else {
sender.sendMessage("§6源: §e" + string.getKey() + " §c未找到任何仓库信息 已删除!");
keys.remove();
}
}
return true;
}
public boolean updateRepositories(CommandSender sender, final Repositories repocenter) {
if (sender == null) {
sender = Bukkit.getConsoleSender();
}
if (repocenter == null || repocenter.repos.isEmpty()) {
return false;
}
for (final Repository repo : repocenter.repos) {
addPackage(sender, repo.url);
}
return true;
}
private String handerRepoUrl(String url) {
final int urllength = url.length();
url = url.substring(0, url.endsWith("/") ? urllength - 1 : urllength);
if (!url.startsWith("http://")) {
url = "http://" + url;
}
if (!url.endsWith("repo.info")) {
url = url + "/repo.info";
}
return url;
}
} }