mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-12-23 05:08:47 +00:00
去除离线缓存 修复版本更新模块...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
d1fd6daa9a
commit
5f69c0abbd
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<artifactId>Yum</artifactId>
|
||||
<version>1.9.6</version>
|
||||
<version>1.9.7</version>
|
||||
<name>Yum</name>
|
||||
<description>Minecraft 服务器插件管理系统</description>
|
||||
<build>
|
||||
@ -55,7 +55,7 @@
|
||||
</build>
|
||||
<properties>
|
||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||
<update.description>&c修复没有Gson的服务端仓库管理出错的问题...</update.description>
|
||||
<update.description>&c去除离线缓存 修复版本更新模块...</update.description>
|
||||
<env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
@ -14,29 +14,24 @@ import cn.citycraft.Yum.file.commands.FileCommand;
|
||||
/**
|
||||
* MC插件仓库
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月21日下午5:14:39
|
||||
* @author 喵♂呜
|
||||
* @since 2015年8月21日下午5:14:39
|
||||
*/
|
||||
public class Yum extends JavaPlugin {
|
||||
public FileConfig config;
|
||||
public FileConfig config;
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
YumAPI.getRepo().cacheToJson(config);
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new YumAPI(this);
|
||||
new YumCommand(this);
|
||||
new FileCommand(this);
|
||||
new VersionChecker(this);
|
||||
YumAPI.updaterepo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new YumAPI(this);
|
||||
new YumCommand(this);
|
||||
new FileCommand(this);
|
||||
YumAPI.getRepo().jsonToCache(config);
|
||||
YumAPI.updaterepo();
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig(this);
|
||||
}
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,316 +20,318 @@ import cn.citycraft.Yum.manager.RepositoryManager;
|
||||
/**
|
||||
* Yum管理中心
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年9月1日上午10:59:47
|
||||
* @author 喵♂呜
|
||||
* @since 2015年9月1日上午10:59:47
|
||||
*/
|
||||
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管理中心
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public YumAPI(final Plugin plugin) {
|
||||
YumAPI.main = plugin;
|
||||
plugman = new PluginsManager(main);
|
||||
download = new DownloadManager(main);
|
||||
repo = new RepositoryManager(main);
|
||||
}
|
||||
/**
|
||||
* 初始化Yum管理中心
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public YumAPI(final Plugin plugin) {
|
||||
YumAPI.main = plugin;
|
||||
plugman = new PluginsManager(main);
|
||||
download = new DownloadManager(main);
|
||||
repo = new RepositoryManager(main);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void delete(final Plugin plugin) {
|
||||
plugman.deletePlugin(plugin);
|
||||
}
|
||||
/**
|
||||
* 删除插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void delete(final Plugin plugin) {
|
||||
plugman.deletePlugin(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得下载管理器
|
||||
*
|
||||
* @return {@link DownloadManager}
|
||||
*/
|
||||
public static DownloadManager getDownload() {
|
||||
return download;
|
||||
}
|
||||
/**
|
||||
* 获得下载管理器
|
||||
*
|
||||
* @return {@link DownloadManager}
|
||||
*/
|
||||
public static DownloadManager getDownload() {
|
||||
return download;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得插件管理器
|
||||
*
|
||||
* @return {@link PluginsManager}
|
||||
*/
|
||||
public static PluginsManager getPlugman() {
|
||||
return plugman;
|
||||
}
|
||||
/**
|
||||
* 获得插件管理器
|
||||
*
|
||||
* @return {@link PluginsManager}
|
||||
*/
|
||||
public static PluginsManager getPlugman() {
|
||||
return plugman;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得仓库管理器
|
||||
*
|
||||
* @return {@link RepositoryManager}
|
||||
*/
|
||||
public static RepositoryManager getRepo() {
|
||||
return repo;
|
||||
}
|
||||
/**
|
||||
* 获得仓库管理器
|
||||
*
|
||||
* @return {@link RepositoryManager}
|
||||
*/
|
||||
public static RepositoryManager getRepo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean install(final CommandSender sender, final String pluginname, final String url) {
|
||||
final File pluginFile = new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar");
|
||||
if (download.run(sender, url, pluginFile)) {
|
||||
return plugman.load(sender, pluginFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean install(final CommandSender sender, final String pluginname, final String url) {
|
||||
final File pluginFile = new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar");
|
||||
if (download.run(sender, url, pluginFile)) {
|
||||
return plugman.load(sender, pluginFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean install(final String pluginname, final String url) {
|
||||
return install(null, pluginname, url);
|
||||
}
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean install(final String pluginname, final String url) {
|
||||
return install(null, pluginname, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean installfromyum(final CommandSender sender, final String pluginname) {
|
||||
return installfromyum(sender, pluginname, null);
|
||||
}
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean installfromyum(final CommandSender sender, final String pluginname) {
|
||||
return installfromyum(sender, pluginname, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) {
|
||||
final PluginInfo pi = repo.getPlugin(pluginname);
|
||||
if (pi != null) {
|
||||
return install(sender, pi.name, pi.getUrl(sender, version));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 是否安装成功
|
||||
*/
|
||||
public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) {
|
||||
final PluginInfo pi = repo.getPlugin(pluginname);
|
||||
if (pi != null) {
|
||||
return install(sender, pi.name, pi.getUrl(sender, version));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入插件
|
||||
*
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
*/
|
||||
public static void load(final File pluginFile) {
|
||||
plugman.load(pluginFile);
|
||||
}
|
||||
/**
|
||||
* 载入插件
|
||||
*
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
*/
|
||||
public static void load(final File pluginFile) {
|
||||
plugman.load(pluginFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入插件
|
||||
*
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
*/
|
||||
public static void load(final String pluginname) {
|
||||
plugman.load(pluginname);
|
||||
}
|
||||
/**
|
||||
* 载入插件
|
||||
*
|
||||
* @param pluginname
|
||||
* 插件名称
|
||||
*/
|
||||
public static void load(final String pluginname) {
|
||||
plugman.load(pluginname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void reload(final Plugin plugin) {
|
||||
plugman.reload(plugin);
|
||||
}
|
||||
/**
|
||||
* 重载插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void reload(final Plugin plugin) {
|
||||
plugman.reload(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 卸载插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void unload(final Plugin plugin) {
|
||||
plugman.unload(plugin);
|
||||
}
|
||||
/**
|
||||
* 卸载插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void unload(final Plugin plugin) {
|
||||
plugman.unload(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param url
|
||||
* 新插件的下载地址
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
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()))) {
|
||||
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
|
||||
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param url
|
||||
* 新插件的下载地址
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
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()))) {
|
||||
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
|
||||
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param url
|
||||
* 新插件的下载地址
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
public static boolean update(final Plugin plugin, final URL url) {
|
||||
return update(null, plugin, url);
|
||||
}
|
||||
/**
|
||||
* 更新插件
|
||||
*
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param url
|
||||
* 新插件的下载地址
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
public static boolean update(final Plugin plugin, final URL url) {
|
||||
return update(null, plugin, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新支持Yum的插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
*/
|
||||
public static void updateall(final CommandSender sender) {
|
||||
final List<Plugin> ulist = new ArrayList<>();
|
||||
try {
|
||||
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
|
||||
ulist.add(updateplugin.getValue());
|
||||
}
|
||||
UpdatePlugin.clearList();
|
||||
} catch (final Exception | Error e) {
|
||||
try {
|
||||
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
|
||||
ulist.addAll(updatelist.keySet());
|
||||
UpdatePlugin.getList().clear();
|
||||
} catch (final Exception | Error e2) {
|
||||
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
|
||||
sender.sendMessage("§4异常: §c" + e2.getMessage());
|
||||
}
|
||||
}
|
||||
if (ulist.size() > 0) {
|
||||
for (final Plugin updateplugin : ulist) {
|
||||
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
|
||||
updatefromyum(sender, updateplugin, null, true);
|
||||
}
|
||||
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
||||
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
||||
} else {
|
||||
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 更新支持Yum的插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
*/
|
||||
public static void updateall(final CommandSender sender) {
|
||||
final List<Plugin> ulist = new ArrayList<>();
|
||||
try {
|
||||
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
|
||||
ulist.add(updateplugin.getValue());
|
||||
}
|
||||
UpdatePlugin.clearList();
|
||||
} catch (final Exception | Error e) {
|
||||
try {
|
||||
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
|
||||
ulist.addAll(updatelist.keySet());
|
||||
UpdatePlugin.getList().clear();
|
||||
} catch (final Exception | Error e2) {
|
||||
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
|
||||
sender.sendMessage("§4异常: §c" + e2.getMessage());
|
||||
}
|
||||
}
|
||||
if (ulist.size() > 0) {
|
||||
for (final Plugin updateplugin : ulist) {
|
||||
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
|
||||
updatefromyum(sender, updateplugin, null, true);
|
||||
}
|
||||
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
||||
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
||||
} else {
|
||||
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) {
|
||||
return updatefromyum(sender, plugin, null);
|
||||
}
|
||||
/**
|
||||
* 更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) {
|
||||
return updatefromyum(sender, plugin, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Yum内部更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param version
|
||||
* 插件版本(null则自动获取)
|
||||
* @return
|
||||
*/
|
||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
|
||||
return updatefromyum(sender, plugin, version, false);
|
||||
}
|
||||
/**
|
||||
* 从Yum内部更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param version
|
||||
* 插件版本(null则自动获取)
|
||||
* @return
|
||||
*/
|
||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
|
||||
return updatefromyum(sender, plugin, version, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Yum内部更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param version
|
||||
* 插件版本(null则自动获取)
|
||||
* @param oneKeyUpdate
|
||||
* 是否一键更新
|
||||
* @return
|
||||
*/
|
||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) {
|
||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||
if (pi != null) {
|
||||
if (download.run(sender, pi.getUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
||||
if (!oneKeyUpdate) {
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 从Yum内部更新插件
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
* @param version
|
||||
* 插件版本(null则自动获取)
|
||||
* @param oneKeyUpdate
|
||||
* 是否一键更新
|
||||
* @return
|
||||
*/
|
||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) {
|
||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||
if (pi != null) {
|
||||
final File pFile = new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName());
|
||||
if (download.run(sender, pi.getUrl(sender, version), pFile)) {
|
||||
|
||||
/**
|
||||
* 更新Yum源数据
|
||||
*/
|
||||
public static void updaterepo() {
|
||||
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
repo.updateRepositories(Bukkit.getConsoleSender());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!oneKeyUpdate) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void upgrade(final CommandSender sender, final Plugin plugin) {
|
||||
plugman.upgrade(sender, plugin);
|
||||
}
|
||||
/**
|
||||
* 更新Yum源数据
|
||||
*/
|
||||
public static void updaterepo() {
|
||||
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
repo.updateRepositories(Bukkit.getConsoleSender());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public static void upgrade(final CommandSender sender, final Plugin plugin) {
|
||||
plugman.upgrade(sender, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
public CommandDelete(final Yum main) {
|
||||
super("del");
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("删除插件");
|
||||
setPossibleArguments("<插件名称>");
|
||||
}
|
||||
public CommandDelete(final Yum main) {
|
||||
super("del");
|
||||
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().deletePlugin(sender, plugin)) {
|
||||
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
|
||||
} else {
|
||||
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
}
|
||||
@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().deletePlugin(sender, plugin)) {
|
||||
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
|
||||
} else {
|
||||
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
public CommandFullDelete(final Yum main) {
|
||||
super("fdel");
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("删除插件以及数据文件夹");
|
||||
setPossibleArguments("<插件名称>");
|
||||
}
|
||||
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 + " 不存在或已卸载!");
|
||||
}
|
||||
}
|
||||
@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 + " 不存在或已卸载!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandInfo(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("查看插件详情");
|
||||
setPossibleArguments("<插件名称>");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandInfo(final Yum main) {
|
||||
super();
|
||||
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 = main.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
final PluginDescriptionFile desc = plugin.getDescription();
|
||||
sender.sendMessage("§6插件名称: §3" + plugin.getName());
|
||||
sender.sendMessage("§6插件版本: §3" + desc.getVersion());
|
||||
sender.sendMessage("§6插件作者: §3" + StringUtils.join(desc.getAuthors(), " "));
|
||||
sender.sendMessage("§6插件描述: §3" + (desc.getDescription() == null ? "无" : desc.getDescription()));
|
||||
sender.sendMessage("§6插件依赖: §3" + (desc.getDepend().isEmpty() ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
|
||||
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().isEmpty() ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
|
||||
final Map<String, Map<String, Object>> clist = desc.getCommands();
|
||||
if (clist != null) {
|
||||
sender.sendMessage("§6插件注册命令: §3" + (clist.isEmpty() ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, clist.keySet(), "§6 - §a");
|
||||
}
|
||||
final List<Permission> plist = desc.getPermissions();
|
||||
if (plist != null) {
|
||||
sender.sendMessage("§6插件注册权限: " + (plist.isEmpty() ? "无" : ""));
|
||||
for (final Permission perm : plist) {
|
||||
sender.sendMessage("§6 - §a" + perm.getName() + "§6 - §e" + (perm.getDescription().isEmpty() ? "无描述" : perm.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath());
|
||||
} else {
|
||||
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
}
|
||||
@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 = main.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
final PluginDescriptionFile desc = plugin.getDescription();
|
||||
sender.sendMessage("§6插件名称: §3" + plugin.getName());
|
||||
sender.sendMessage("§6插件版本: §3" + desc.getVersion());
|
||||
sender.sendMessage("§6插件作者: §3" + StringUtils.join(desc.getAuthors(), " "));
|
||||
sender.sendMessage("§6插件描述: §3" + (desc.getDescription() == null ? "无" : desc.getDescription()));
|
||||
sender.sendMessage("§6插件依赖: §3" + (desc.getDepend().isEmpty() ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
|
||||
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().isEmpty() ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
|
||||
final Map<String, Map<String, Object>> clist = desc.getCommands();
|
||||
if (clist != null) {
|
||||
sender.sendMessage("§6插件注册命令: §3" + (clist.isEmpty() ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, clist.keySet(), "§6 - §a");
|
||||
}
|
||||
final List<Permission> plist = desc.getPermissions();
|
||||
if (plist != null) {
|
||||
sender.sendMessage("§6插件注册权限: " + (plist.isEmpty() ? "无" : ""));
|
||||
for (final Permission perm : plist) {
|
||||
sender.sendMessage("§6 - §a" + perm.getName() + "§6 - §e" + (perm.getDescription().isEmpty() ? "无描述" : perm.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath());
|
||||
} else {
|
||||
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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")) {
|
||||
return StringUtil.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
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")) {
|
||||
return StringUtil.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandInstall(final Yum main) {
|
||||
super("i");
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("安装插件");
|
||||
setPossibleArguments("<插件名称>");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandInstall(final Yum main) {
|
||||
super("i");
|
||||
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) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length < 2) {
|
||||
YumAPI.installfromyum(sender, pluginname);
|
||||
} else {
|
||||
YumAPI.installfromyum(sender, pluginname, args[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage("§c插件" + pluginname + "已安装在服务器 需要更新请使用yum update " + pluginname + "!");
|
||||
}
|
||||
}
|
||||
@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) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length < 2) {
|
||||
YumAPI.installfromyum(sender, pluginname);
|
||||
} else {
|
||||
YumAPI.installfromyum(sender, pluginname, args[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage("§c插件" + pluginname + "已安装在服务器 需要更新请使用yum update " + pluginname + "!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
if (args[0].equalsIgnoreCase("install")) {
|
||||
return StringUtil.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
if (args[0].equalsIgnoreCase("install")) {
|
||||
return StringUtil.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandList(final Yum main) {
|
||||
super("l");
|
||||
this.main = main;
|
||||
setDescription("列出已安装插件列表");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandList(final Yum main) {
|
||||
super("l");
|
||||
this.main = main;
|
||||
setDescription("列出已安装插件列表");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
sender.sendMessage("§6- " + YumAPI.getPlugman().getFormattedName(plugin, true));
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
sender.sendMessage("§6- " + YumAPI.getPlugman().getFormattedName(plugin, true));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandLoad(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("载入插件");
|
||||
setPossibleArguments("<插件名称>");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandLoad(final Yum main) {
|
||||
super();
|
||||
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) {
|
||||
YumAPI.getPlugman().load(sender, pluginname);
|
||||
} else {
|
||||
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
||||
}
|
||||
};
|
||||
@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) {
|
||||
YumAPI.getPlugman().load(sender, pluginname);
|
||||
} else {
|
||||
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandReload(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("重载插件");
|
||||
setPossibleArguments("<插件名称|all|*>");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandReload(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("重载插件");
|
||||
setPossibleArguments("<插件名称|all|*>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final String pluginname = args[0];
|
||||
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
|
||||
YumAPI.getPlugman().reloadAll(sender);
|
||||
return;
|
||||
}
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
YumAPI.getPlugman().reload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
final String pluginname = args[0];
|
||||
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
|
||||
YumAPI.getPlugman().reloadAll(sender);
|
||||
return;
|
||||
}
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
YumAPI.getPlugman().reload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandRepo(final Yum main) {
|
||||
super("r");
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("插件源命令");
|
||||
setPossibleArguments("<add|del|all|clean|list> <仓库名称>");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandRepo(final Yum main) {
|
||||
super("r");
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("插件源命令");
|
||||
setPossibleArguments("<add|del|all|clean|list> <仓库名称>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String cmd = args[0];
|
||||
switch (cmd) {
|
||||
case "add":
|
||||
if (args.length == 2) {
|
||||
if (YumAPI.getRepo().addRepositories(sender, args[1])) {
|
||||
final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name;
|
||||
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
|
||||
}
|
||||
break;
|
||||
case "del":
|
||||
if (args.length == 2) {
|
||||
final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]);
|
||||
if (delrepo != null) {
|
||||
YumAPI.getRepo().delRepositories(sender, args[1]);
|
||||
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
|
||||
}
|
||||
break;
|
||||
case "delall":
|
||||
YumAPI.getRepo().getRepoCache().getRepos().clear();
|
||||
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
|
||||
break;
|
||||
case "list":
|
||||
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
||||
StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
|
||||
break;
|
||||
case "all":
|
||||
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
|
||||
StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
|
||||
break;
|
||||
case "clean":
|
||||
YumAPI.getRepo().clean();
|
||||
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
||||
break;
|
||||
case "update":
|
||||
YumAPI.getRepo().updateRepositories(sender);
|
||||
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String cmd = args[0];
|
||||
switch (cmd) {
|
||||
case "add":
|
||||
if (args.length == 2) {
|
||||
if (YumAPI.getRepo().addRepositories(sender, args[1])) {
|
||||
final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name;
|
||||
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
|
||||
}
|
||||
break;
|
||||
case "del":
|
||||
if (args.length == 2) {
|
||||
final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]);
|
||||
if (delrepo != null) {
|
||||
YumAPI.getRepo().delRepositories(sender, args[1]);
|
||||
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
|
||||
}
|
||||
break;
|
||||
case "delall":
|
||||
YumAPI.getRepo().getRepoCache().getRepos().clear();
|
||||
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
|
||||
break;
|
||||
case "list":
|
||||
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
||||
StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
|
||||
break;
|
||||
case "all":
|
||||
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
|
||||
StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
|
||||
break;
|
||||
case "clean":
|
||||
YumAPI.getRepo().clean();
|
||||
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
||||
break;
|
||||
case "update":
|
||||
YumAPI.getRepo().updateRepositories(sender);
|
||||
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
if (args[0].equalsIgnoreCase("repo")) {
|
||||
if (args.length == 2) {
|
||||
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")) {
|
||||
return StringUtil.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
if (args[0].equalsIgnoreCase("repo")) {
|
||||
if (args.length == 2) {
|
||||
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")) {
|
||||
return StringUtil.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUnload(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("卸载插件");
|
||||
setPossibleArguments("<插件名称>");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUnload(final Yum main) {
|
||||
super();
|
||||
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) {
|
||||
YumAPI.getPlugman().unload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
@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) {
|
||||
YumAPI.getPlugman().unload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -14,37 +14,49 @@ import cn.citycraft.Yum.Yum;
|
||||
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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
public CommandUpdate(final Yum main) {
|
||||
super("u");
|
||||
this.main = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("更新插件");
|
||||
setPossibleArguments("<插件名称> [插件版本]");
|
||||
}
|
||||
public CommandUpdate(final Yum main) {
|
||||
super("u");
|
||||
this.main = main;
|
||||
setMinimumArguments(0);
|
||||
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);
|
||||
sender.sendMessage("§a开始更新插件: " + pluginname);
|
||||
if (plugin != null) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length < 2) {
|
||||
YumAPI.updatefromyum(sender, plugin);
|
||||
} else {
|
||||
YumAPI.updatefromyum(sender, plugin, args[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
YumAPI.getRepo().updateRepositories(sender);
|
||||
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
sender.sendMessage("§a开始更新插件: " + pluginname);
|
||||
if (plugin != null) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length < 2) {
|
||||
YumAPI.updatefromyum(sender, plugin);
|
||||
} else {
|
||||
YumAPI.updatefromyum(sender, plugin, args[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sendHelp(sender, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,25 +13,26 @@ import cn.citycraft.Yum.Yum;
|
||||
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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
public CommandUpdateAll(final Yum main) {
|
||||
super("ua");
|
||||
this.main = main;
|
||||
setDescription("更新所有可更新插件");
|
||||
}
|
||||
public CommandUpdateAll(final Yum main) {
|
||||
super("ua");
|
||||
this.main = main;
|
||||
setDescription("更新所有可更新插件");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
sender.sendMessage("§d开始更新服务器可更新插件");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
YumAPI.updateall(sender);
|
||||
}
|
||||
});
|
||||
};
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
sender.sendMessage("§d开始更新服务器可更新插件");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
YumAPI.updateall(sender);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -14,39 +14,40 @@ import cn.citycraft.Yum.Yum;
|
||||
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 {
|
||||
Yum main;
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUpgrade(final Yum main) {
|
||||
super("ug");
|
||||
this.main = main;
|
||||
setDescription("升级插件");
|
||||
setPossibleArguments("[插件名称]");
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUpgrade(final Yum main) {
|
||||
super("ug");
|
||||
this.main = main;
|
||||
setDescription("升级插件");
|
||||
setPossibleArguments("[插件名称]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length == 0) {
|
||||
YumAPI.getPlugman().upgrade(sender);
|
||||
} else {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
sender.sendMessage("§a开始升级插件: " + pluginname);
|
||||
if (plugin != null) {
|
||||
YumAPI.upgrade(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length == 0) {
|
||||
YumAPI.getPlugman().upgrade(sender);
|
||||
} else {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
sender.sendMessage("§a开始升级插件: " + pluginname);
|
||||
if (plugin != null) {
|
||||
YumAPI.upgrade(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -3,21 +3,27 @@ package cn.citycraft.Yum.commands;
|
||||
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
||||
import cn.citycraft.Yum.Yum;
|
||||
|
||||
/**
|
||||
* Yum命令基类
|
||||
*
|
||||
* @since 2016年1月9日 上午10:02:24
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class YumCommand {
|
||||
public YumCommand(final Yum yum) {
|
||||
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum");
|
||||
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false));
|
||||
cmdhandler.registerCommand(new CommandList(yum));
|
||||
cmdhandler.registerCommand(new CommandInstall(yum));
|
||||
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));
|
||||
cmdhandler.registerCommand(new CommandLoad(yum));
|
||||
cmdhandler.registerCommand(new CommandUnload(yum));
|
||||
cmdhandler.registerCommand(new CommandUpgrade(yum));
|
||||
}
|
||||
public YumCommand(final Yum yum) {
|
||||
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum");
|
||||
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false));
|
||||
cmdhandler.registerCommand(new CommandList(yum));
|
||||
cmdhandler.registerCommand(new CommandInstall(yum));
|
||||
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));
|
||||
cmdhandler.registerCommand(new CommandLoad(yum));
|
||||
cmdhandler.registerCommand(new CommandUnload(yum));
|
||||
cmdhandler.registerCommand(new CommandUpgrade(yum));
|
||||
}
|
||||
}
|
||||
|
@ -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 CommandDelete(final Yum main) {
|
||||
super("del");
|
||||
setMinimumArguments(1);
|
||||
setDescription("删除文件(服务器JAR为根目录)");
|
||||
setPossibleArguments("<文件相对目录>");
|
||||
}
|
||||
public CommandDelete(final Yum main) {
|
||||
super("del");
|
||||
setMinimumArguments(1);
|
||||
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 {
|
||||
if (file.isDirectory()) {
|
||||
sendMessage(sender, "§e" + file.getAbsolutePath() + " §c是一个目录 请使用file rm!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " " + (file.delete() ? "§a删除成功!" : "§c删除失败!"));
|
||||
} catch (final Exception e) {
|
||||
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " 删除失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@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 {
|
||||
if (file.isDirectory()) {
|
||||
sendMessage(sender, "§e" + file.getAbsolutePath() + " §c是一个目录 请使用file rm!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " " + (file.delete() ? "§a删除成功!" : "§c删除失败!"));
|
||||
} catch (final Exception e) {
|
||||
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " 删除失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum main;
|
||||
DownloadManager dl;
|
||||
Yum main;
|
||||
DownloadManager dl;
|
||||
|
||||
public CommandDownLoad(final Yum main) {
|
||||
super("d");
|
||||
this.main = main;
|
||||
dl = YumAPI.getDownload();
|
||||
setMinimumArguments(1);
|
||||
setDescription("下载文件(默认保存到服务器更新文件夹)");
|
||||
setPossibleArguments("<下载地址> [保存文件路径]");
|
||||
}
|
||||
public CommandDownLoad(final Yum main) {
|
||||
super("d");
|
||||
this.main = main;
|
||||
dl = YumAPI.getDownload();
|
||||
setMinimumArguments(1);
|
||||
setDescription("下载文件(默认保存到服务器更新文件夹)");
|
||||
setPossibleArguments("<下载地址> [保存文件路径]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
String urlstr = args[0];
|
||||
if (!urlstr.startsWith("http")) {
|
||||
urlstr = "http://" + urlstr;
|
||||
}
|
||||
File file = null;
|
||||
if (args.length == 2) {
|
||||
file = new File(args[1]);
|
||||
} else {
|
||||
file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr));
|
||||
}
|
||||
dl.run(sender, urlstr, file);
|
||||
}
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
String urlstr = args[0];
|
||||
if (!urlstr.startsWith("http")) {
|
||||
urlstr = "http://" + urlstr;
|
||||
}
|
||||
File file = null;
|
||||
if (args.length == 2) {
|
||||
file = new File(args[1]);
|
||||
} else {
|
||||
file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr));
|
||||
}
|
||||
dl.run(sender, urlstr, 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 CommandLs(final Yum main) {
|
||||
super("l");
|
||||
setDescription("列出当前目录(服务器JAR为根目录)");
|
||||
setPossibleArguments("<相对目录>");
|
||||
}
|
||||
public CommandLs(final Yum main) {
|
||||
super("l");
|
||||
setDescription("列出当前目录(服务器JAR为根目录)");
|
||||
setPossibleArguments("<相对目录>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
File dir = new File(".");
|
||||
if (args.length == 1) {
|
||||
dir = new File(args[0]);
|
||||
}
|
||||
if (!dir.isDirectory()) {
|
||||
sendMessage(sender, "§6路径: §e " + dir.getAbsolutePath() + " §c不是一个目录!");
|
||||
return;
|
||||
}
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
for (final File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
sb.append("§b");
|
||||
} else {
|
||||
sb.append("§a");
|
||||
}
|
||||
sb.append(file.getName() + " ");
|
||||
}
|
||||
final String filelist = sb.toString();
|
||||
if (filelist.isEmpty()) {
|
||||
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §c下没有文件或文件夹!");
|
||||
} else {
|
||||
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §a存在如下文件!");
|
||||
sendMessage(sender, sb.toString());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
File dir = new File(".");
|
||||
if (args.length == 1) {
|
||||
dir = new File(args[0]);
|
||||
}
|
||||
if (!dir.isDirectory()) {
|
||||
sendMessage(sender, "§6路径: §e " + dir.getAbsolutePath() + " §c不是一个目录!");
|
||||
return;
|
||||
}
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
for (final File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
sb.append("§b");
|
||||
} else {
|
||||
sb.append("§a");
|
||||
}
|
||||
sb.append(file.getName() + " ");
|
||||
}
|
||||
final String filelist = sb.toString();
|
||||
if (filelist.isEmpty()) {
|
||||
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §c下没有文件或文件夹!");
|
||||
} else {
|
||||
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §a存在如下文件!");
|
||||
sendMessage(sender, sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 CommandRename(final Yum main) {
|
||||
super("rn");
|
||||
setMinimumArguments(2);
|
||||
setDescription("重命名文件(服务器JAR为根目录)");
|
||||
setPossibleArguments("<文件相对目录> <文件名称>");
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
Yum plugin;
|
||||
Yum plugin;
|
||||
|
||||
public CommandRm(final Yum main) {
|
||||
super();
|
||||
plugin = main;
|
||||
setMinimumArguments(1);
|
||||
setDescription("删除文件夹(服务器JAR为根目录)");
|
||||
setPossibleArguments("<文件相对目录>");
|
||||
}
|
||||
public CommandRm(final Yum main) {
|
||||
super();
|
||||
plugin = main;
|
||||
setMinimumArguments(1);
|
||||
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 {
|
||||
if (!file.isDirectory()) {
|
||||
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c是一个文件 请使用file delete!");
|
||||
return;
|
||||
}
|
||||
for (final String name : plugin.config.getStringList("blacklist")) {
|
||||
if (file.getAbsolutePath().toLowerCase().endsWith(name)) {
|
||||
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c不允许被删除!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (file.listFiles().length != 0 && !(args.length > 1 && args[1].equalsIgnoreCase("-rf"))) {
|
||||
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " §c不为空!");
|
||||
sendMessage(sender, "§c请使用 §a/file rm " + fpath + " -rf §c强行删除!");
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " " + (FileUtil.deleteDir(sender, file) ? "§a删除成功!" : "§c删除失败!"));
|
||||
}
|
||||
}
|
||||
@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 {
|
||||
if (!file.isDirectory()) {
|
||||
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c是一个文件 请使用file delete!");
|
||||
return;
|
||||
}
|
||||
for (final String name : plugin.config.getStringList("blacklist")) {
|
||||
if (file.getAbsolutePath().toLowerCase().endsWith(name)) {
|
||||
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c不允许被删除!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (file.listFiles().length != 0 && !(args.length > 1 && args[1].equalsIgnoreCase("-rf"))) {
|
||||
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " §c不为空!");
|
||||
sendMessage(sender, "§c请使用 §a/file rm " + fpath + " -rf §c强行删除!");
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " " + (FileUtil.deleteDir(sender, file) ? "§a删除成功!" : "§c删除失败!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,20 @@ package cn.citycraft.Yum.file.commands;
|
||||
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
||||
import cn.citycraft.Yum.Yum;
|
||||
|
||||
/**
|
||||
* File命令基类
|
||||
*
|
||||
* @since 2016年1月9日 上午10:02:39
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
public class FileCommand {
|
||||
public FileCommand(final Yum yum) {
|
||||
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "file");
|
||||
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));
|
||||
}
|
||||
public FileCommand(final Yum yum) {
|
||||
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "file");
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -9,199 +9,207 @@ import java.net.URL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
/**
|
||||
* 下载管理类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月21日下午6:08:09
|
||||
* @author 喵♂呜
|
||||
* @since 2015年8月21日下午6:08:09
|
||||
*/
|
||||
public class DownloadManager {
|
||||
Plugin plugin;
|
||||
Plugin plugin;
|
||||
|
||||
public DownloadManager(final Plugin main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
public DownloadManager(final Plugin main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从地址获得文件名称
|
||||
*
|
||||
* @param url
|
||||
* - 地址
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName(final String url) {
|
||||
final int end = url.lastIndexOf('/');
|
||||
return url.substring(end + 1);
|
||||
}
|
||||
/**
|
||||
* 从地址获得文件名称
|
||||
*
|
||||
* @param url
|
||||
* - 地址
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName(final String url) {
|
||||
final int end = url.lastIndexOf('/');
|
||||
return url.substring(end + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从地址获得文件名称
|
||||
*
|
||||
* @param url
|
||||
* - 地址
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName(final URL url) {
|
||||
return getFileName(url.getFile());
|
||||
}
|
||||
/**
|
||||
* 从地址获得文件名称
|
||||
*
|
||||
* @param url
|
||||
* - 地址
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName(final URL url) {
|
||||
return getFileName(url.getFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final CommandSender sender, final String urlstring) {
|
||||
return run(sender, urlstring, new File("plugins", getFileName(urlstring)));
|
||||
}
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final CommandSender sender, final String urlstring) {
|
||||
return run(sender, urlstring, new File("plugins", getFileName(urlstring)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final CommandSender sender, final String urlstring, final File file) {
|
||||
try {
|
||||
final URL url = new URL(urlstring);
|
||||
return run(sender, url, file);
|
||||
} catch (final MalformedURLException e) {
|
||||
sender.sendMessage("§4错误: §c无法识别的URL地址...");
|
||||
sender.sendMessage("§4地址: §c" + urlstring);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final CommandSender sender, final String urlstring, final File file) {
|
||||
try {
|
||||
final URL url = new URL(urlstring);
|
||||
return run(sender, url, file);
|
||||
} catch (final MalformedURLException e) {
|
||||
sender.sendMessage("§4错误: §c无法识别的URL地址...");
|
||||
sender.sendMessage("§4地址: §c" + urlstring);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param url
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(CommandSender sender, final URL url, final File file) {
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
if (sender == null) {
|
||||
sender = Bukkit.getConsoleSender();
|
||||
}
|
||||
try {
|
||||
sender.sendMessage("§6开始下载: §3" + getFileName(url));
|
||||
sender.sendMessage("§6下载地址: §3" + url.toString());
|
||||
final int fileLength = url.openConnection().getContentLength();
|
||||
if (fileLength < 0) {
|
||||
sender.sendMessage("§6下载: §c文件 " + file.getName() + " 获取长度错误(可能是网络问题)!");
|
||||
sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("§6文件长度: §3" + fileLength);
|
||||
in = new BufferedInputStream(url.openStream());
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
sender.sendMessage("§6创建新目录: §d" + file.getParentFile().getAbsolutePath());
|
||||
}
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
sender.sendMessage("§6创建新文件: §d" + file.getAbsolutePath());
|
||||
fout = new FileOutputStream(file);
|
||||
final byte[] data = new byte[1024];
|
||||
long downloaded = 0L;
|
||||
int count;
|
||||
long time = System.currentTimeMillis();
|
||||
while ((count = in.read(data)) != -1) {
|
||||
downloaded += count;
|
||||
fout.write(data, 0, count);
|
||||
final int percent = (int) (downloaded * 100L / fileLength);
|
||||
if (percent % 10 == 0) {
|
||||
if (System.currentTimeMillis() - time > 500) {
|
||||
sender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent));
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage("§6文件: §a " + file.getName() + " 下载完成!");
|
||||
return true;
|
||||
} catch (final Exception ex) {
|
||||
sender.sendMessage("§6异常: §c" + ex.getMessage());
|
||||
sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!");
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (fout != null) {
|
||||
fout.close();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param url
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(CommandSender sender, final URL url, final File file) {
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
if (sender == null) {
|
||||
sender = Bukkit.getConsoleSender();
|
||||
}
|
||||
try {
|
||||
sender.sendMessage("§6开始下载: §3" + getFileName(url));
|
||||
sender.sendMessage("§6下载地址: §3" + url.toString());
|
||||
final int fileLength = url.openConnection().getContentLength();
|
||||
if (fileLength < 0) {
|
||||
sender.sendMessage("§6下载: §c文件 " + file.getName() + " 获取长度错误(可能是网络问题)!");
|
||||
sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("§6文件长度: §3" + fileLength);
|
||||
in = new BufferedInputStream(url.openStream());
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
sender.sendMessage("§6创建新目录: §d" + file.getParentFile().getAbsolutePath());
|
||||
}
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
sender.sendMessage("§6创建新文件: §d" + file.getAbsolutePath());
|
||||
fout = new FileOutputStream(file);
|
||||
final byte[] data = new byte[1024];
|
||||
long downloaded = 0L;
|
||||
int count;
|
||||
long time = System.currentTimeMillis();
|
||||
while ((count = in.read(data)) != -1) {
|
||||
downloaded += count;
|
||||
fout.write(data, 0, count);
|
||||
final int percent = (int) (downloaded * 100L / fileLength);
|
||||
if (percent % 10 == 0) {
|
||||
if (System.currentTimeMillis() - time > 500) {
|
||||
sender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent));
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
String pVer = null;
|
||||
try {
|
||||
final PluginDescriptionFile desc = plugin.getPluginLoader().getPluginDescription(file);
|
||||
pVer = desc.getVersion();
|
||||
} catch (final Exception e) {
|
||||
pVer = "";
|
||||
}
|
||||
sender.sendMessage("§6" + (pVer.isEmpty() ? "文件" : "插件") + ": §b" + file.getName() + (pVer.isEmpty() ? "" : " 版本 §e" + pVer) + " §a下载完成!");
|
||||
return true;
|
||||
} catch (final Exception ex) {
|
||||
sender.sendMessage("§6异常: §c" + ex.getMessage());
|
||||
sender.sendMessage("§6文件: §c" + file.getName() + " 下载失败!");
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (fout != null) {
|
||||
fout.close();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final String urlstring) {
|
||||
return run(null, urlstring);
|
||||
}
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final String urlstring) {
|
||||
return run(null, urlstring);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final String urlstring, final File file) {
|
||||
return run(null, urlstring, file);
|
||||
}
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param urlstring
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final String urlstring, final File file) {
|
||||
return run(null, urlstring, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param url
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final URL url, final File file) {
|
||||
return run(null, url, file);
|
||||
}
|
||||
/**
|
||||
* 从网络下载文件
|
||||
*
|
||||
* @param url
|
||||
* - 下载地址
|
||||
* @param file
|
||||
* - 保存文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean run(final URL url, final File file) {
|
||||
return run(null, url, file);
|
||||
}
|
||||
|
||||
private String getPer(final int per) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
if (per > i) {
|
||||
sb.append("==");
|
||||
} else if (per == i) {
|
||||
sb.append("> ");
|
||||
} else {
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
private String getPer(final int per) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
if (per > i) {
|
||||
sb.append("==");
|
||||
} else if (per == i) {
|
||||
sb.append("> ");
|
||||
} else {
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,113 +10,113 @@ import cn.citycraft.Yum.manager.RepoSerialization.TagInfo;
|
||||
import cn.citycraft.Yum.manager.RepoSerialization.URLType;
|
||||
|
||||
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 name;
|
||||
public Plugin plugin;
|
||||
public String pom;
|
||||
public URLType type;
|
||||
public String repo;
|
||||
public String url;
|
||||
public String branch;
|
||||
public String name;
|
||||
public Plugin plugin;
|
||||
public String pom;
|
||||
public URLType type;
|
||||
public String repo;
|
||||
public String url;
|
||||
|
||||
/**
|
||||
* 获得下载直链
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param version
|
||||
* 版本
|
||||
* @return 下载直链
|
||||
*/
|
||||
public String getDirectUrl() {
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* 获得下载直链
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param version
|
||||
* 版本
|
||||
* @return 下载直链
|
||||
*/
|
||||
public String getDirectUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得下载直链
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param version
|
||||
* 版本
|
||||
* @return 下载直链
|
||||
*/
|
||||
public String getDirectUrl(final String version) {
|
||||
return url.replace("[version]", version);
|
||||
}
|
||||
/**
|
||||
* 获得下载直链
|
||||
*
|
||||
* @param sender
|
||||
* 命令发送者
|
||||
* @param version
|
||||
* 版本
|
||||
* @return 下载直链
|
||||
*/
|
||||
public String getDirectUrl(final String version) {
|
||||
return url.replace("[version]", version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文件名称
|
||||
*
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName() {
|
||||
return getFileName(plugin.version);
|
||||
}
|
||||
/**
|
||||
* 获得文件名称
|
||||
*
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName() {
|
||||
return getFileName(plugin.version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文件名称
|
||||
*
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName(final String version) {
|
||||
return String.format("%1$s-%2$s.jar", plugin.artifactId, version);
|
||||
}
|
||||
/**
|
||||
* 获得文件名称
|
||||
*
|
||||
* @param version
|
||||
* 插件版本
|
||||
* @return 文件名称
|
||||
*/
|
||||
public String getFileName(final String version) {
|
||||
return String.format("%1$s-%2$s.jar", plugin.artifactId, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Maven仓库指定插件的下载地址
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param version
|
||||
* - 需要更新的版本
|
||||
* @return 更新地址
|
||||
*/
|
||||
public String getMavenUrl(final String ver) {
|
||||
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar",
|
||||
plugin.groupId.replace(".", "/"),
|
||||
plugin.artifactId,
|
||||
(ver == null || ver.isEmpty()) ? plugin.version : ver);
|
||||
}
|
||||
/**
|
||||
* 获取Maven仓库指定插件的下载地址
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param version
|
||||
* - 需要更新的版本
|
||||
* @return 更新地址
|
||||
*/
|
||||
public String getMavenUrl(final String ver) {
|
||||
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar",
|
||||
plugin.groupId.replace(".", "/"),
|
||||
plugin.artifactId,
|
||||
(ver == null || ver.isEmpty()) ? plugin.version : ver);
|
||||
}
|
||||
|
||||
public String getUrl(final CommandSender sender, final String version) {
|
||||
String ver = version;
|
||||
if (ver == null) {
|
||||
if (plugin.tags != null) {
|
||||
PluginHelperLogger.getLogger().debug("发现存在TAG标签 开始检索: " + NMSVersion);
|
||||
for (final TagInfo tagInfo : plugin.tags) {
|
||||
if (tagInfo.tag.equalsIgnoreCase(NMSVersion)) {
|
||||
sender.sendMessage("§6版本: §b从Tag标签中获取 §e" + NMSVersion + " §b的最新版本...");
|
||||
ver = tagInfo.version;
|
||||
if (tagInfo.type == URLType.DirectUrl) {
|
||||
return tagInfo.url;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (pom != null && !pom.isEmpty()) {
|
||||
pom = pom.replace("[name]", name).replace("[branch]", branch);
|
||||
sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本...");
|
||||
ver = IOUtil.getXMLTag(pom, "version", plugin.version);
|
||||
if (ver != null) {
|
||||
sender.sendMessage("§6版本: §a成功获取到最新版本 §e" + ver + " §a...");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ver == null) {
|
||||
ver = plugin.version;
|
||||
sender.sendMessage("§6版本: §a使用缓存的版本 §e" + ver + " §a...");
|
||||
}
|
||||
switch (type) {
|
||||
case DirectUrl:
|
||||
return getDirectUrl(ver);
|
||||
case Maven:
|
||||
return getMavenUrl(ver);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public String getUrl(final CommandSender sender, final String version) {
|
||||
String ver = version;
|
||||
if (ver == null) {
|
||||
if (plugin.tags != null) {
|
||||
PluginHelperLogger.getLogger().debug("发现存在TAG标签 开始检索: " + NMSVersion);
|
||||
for (final TagInfo tagInfo : plugin.tags) {
|
||||
if (tagInfo.tag.equalsIgnoreCase(NMSVersion)) {
|
||||
sender.sendMessage("§6版本: §b从Tag标签中获取 §e" + NMSVersion + " §b的最新版本...");
|
||||
ver = tagInfo.version;
|
||||
if (tagInfo.type == URLType.DirectUrl) {
|
||||
return tagInfo.url;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (pom != null && !pom.isEmpty()) {
|
||||
pom = pom.replace("[name]", name).replace("[branch]", branch);
|
||||
sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本...");
|
||||
ver = IOUtil.getXMLTag(pom, "version", null);
|
||||
if (ver != null) {
|
||||
sender.sendMessage("§6版本: §a成功获取到最新版本 §e" + ver + " §a...");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ver == null) {
|
||||
ver = plugin.version;
|
||||
sender.sendMessage("§6版本: §d使用缓存的版本 §e" + ver + " §a...");
|
||||
}
|
||||
switch (type) {
|
||||
case DirectUrl:
|
||||
return getDirectUrl(ver);
|
||||
case Maven:
|
||||
return getMavenUrl(ver);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -6,72 +6,77 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cn.citycraft.PluginHelper.PluginHelperLogger;
|
||||
import cn.citycraft.PluginHelper.jsonresult.JsonHandle;
|
||||
import cn.citycraft.PluginHelper.utils.IOUtil;
|
||||
import cn.citycraft.Yum.manager.RepoSerialization.Repositories;
|
||||
|
||||
public class RepoCache {
|
||||
Map<String, PluginInfo> plugins = new HashMap<String, PluginInfo>();
|
||||
Map<String, Repositories> repos = new HashMap<String, Repositories>();
|
||||
PluginHelperLogger logger = PluginHelperLogger.getLogger();
|
||||
Map<String, PluginInfo> plugins = new HashMap<String, PluginInfo>();
|
||||
Map<String, Repositories> repos = new HashMap<String, Repositories>();
|
||||
|
||||
public static RepoCache fromJson(final String json) {
|
||||
return JsonHandle.fromJson(json, RepoCache.class);
|
||||
}
|
||||
public static RepoCache fromJson(final String json) {
|
||||
return JsonHandle.fromJson(json, RepoCache.class);
|
||||
}
|
||||
|
||||
public void addPlugins(final String name, final PluginInfo info) {
|
||||
plugins.put(name, info);
|
||||
}
|
||||
public void addPlugins(final String name, final PluginInfo info) {
|
||||
plugins.put(name, info);
|
||||
}
|
||||
|
||||
public Repositories addRepo(final String repo) {
|
||||
if (repos.containsKey(repo) || repo.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final Repositories reposes = getRepo(repo);
|
||||
if (reposes == null) {
|
||||
return null;
|
||||
}
|
||||
repos.put(repo, reposes);
|
||||
return reposes;
|
||||
}
|
||||
public Repositories addRepo(final String repo) {
|
||||
if (repos.containsKey(repo) || repo.isEmpty()) {
|
||||
logger.debug("源地址为空或已存在 " + repo);
|
||||
return null;
|
||||
}
|
||||
final Repositories reposes = getRepo(repo);
|
||||
if (reposes == null) {
|
||||
return null;
|
||||
}
|
||||
repos.put(repo, reposes);
|
||||
return reposes;
|
||||
}
|
||||
|
||||
public List<String> getAllRepoInfo() {
|
||||
final List<String> repoinfo = new ArrayList<String>();
|
||||
for (final Entry<String, Repositories> repo : repos.entrySet()) {
|
||||
repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey()));
|
||||
}
|
||||
return repoinfo;
|
||||
}
|
||||
public List<String> getAllRepoInfo() {
|
||||
final List<String> repoinfo = new ArrayList<String>();
|
||||
for (final Entry<String, Repositories> repo : repos.entrySet()) {
|
||||
repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey()));
|
||||
}
|
||||
return repoinfo;
|
||||
}
|
||||
|
||||
public Map<String, PluginInfo> getPlugins() {
|
||||
return plugins;
|
||||
}
|
||||
public Map<String, PluginInfo> getPlugins() {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public Repositories getRepo(final String repo) {
|
||||
final String json = IOUtil.getData(repo);
|
||||
if (json == null || json.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final Repositories reposes = JsonHandle.fromJson(json, Repositories.class);
|
||||
if (reposes == null || reposes.repos.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return reposes;
|
||||
}
|
||||
public Repositories getRepo(final String repo) {
|
||||
final String json = IOUtil.getData(repo);
|
||||
if (json == null || json.isEmpty()) {
|
||||
logger.debug("源地址获取数据为空 " + repo);
|
||||
return null;
|
||||
}
|
||||
final Repositories reposes = JsonHandle.fromJson(json, Repositories.class);
|
||||
if (reposes == null || reposes.repos.isEmpty()) {
|
||||
logger.debug("源地址解析Json为空 " + repo);
|
||||
return null;
|
||||
}
|
||||
return reposes;
|
||||
}
|
||||
|
||||
public Map<String, Repositories> getRepos() {
|
||||
return repos;
|
||||
}
|
||||
public Map<String, Repositories> getRepos() {
|
||||
return repos;
|
||||
}
|
||||
|
||||
public boolean removeRepo(final String repo) {
|
||||
if (repo.isEmpty() || !repos.containsKey(repo)) {
|
||||
return false;
|
||||
}
|
||||
repos.remove(repo);
|
||||
return true;
|
||||
}
|
||||
public boolean removeRepo(final String repo) {
|
||||
if (repo.isEmpty() || !repos.containsKey(repo)) {
|
||||
return false;
|
||||
}
|
||||
repos.remove(repo);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonHandle.toJson(this);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonHandle.toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -9,51 +9,51 @@ import java.util.List;
|
||||
/**
|
||||
* 源仓库序列化类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月31日下午7:41:53
|
||||
* @author 喵♂呜
|
||||
* @since 2015年8月31日下午7:41:53
|
||||
*/
|
||||
public class RepoSerialization {
|
||||
public class PackageInfo {
|
||||
public String name;
|
||||
public List<Plugin> plugins = new ArrayList<>();
|
||||
public String pom;
|
||||
public String url;
|
||||
public URLType type;
|
||||
}
|
||||
public class PackageInfo {
|
||||
public String name;
|
||||
public List<Plugin> plugins = new ArrayList<>();
|
||||
public String pom;
|
||||
public String url;
|
||||
public URLType type;
|
||||
}
|
||||
|
||||
public class Plugin {
|
||||
public String artifactId;
|
||||
public String branch;
|
||||
public String description;
|
||||
public String groupId;
|
||||
public String name;
|
||||
public String url;
|
||||
public String pom;
|
||||
public List<TagInfo> tags;
|
||||
public String version;
|
||||
public URLType type;
|
||||
}
|
||||
public class Plugin {
|
||||
public String artifactId;
|
||||
public String branch;
|
||||
public String description;
|
||||
public String groupId;
|
||||
public String name;
|
||||
public String url;
|
||||
public String pom;
|
||||
public List<TagInfo> tags;
|
||||
public String version;
|
||||
public URLType type;
|
||||
}
|
||||
|
||||
public class Repositories {
|
||||
public String name;
|
||||
public List<Repository> repos;
|
||||
}
|
||||
public class Repositories {
|
||||
public String name;
|
||||
public List<Repository> repos;
|
||||
}
|
||||
|
||||
public class Repository {
|
||||
public String id;
|
||||
public URLType type;
|
||||
public String url;
|
||||
}
|
||||
public class Repository {
|
||||
public String id;
|
||||
public URLType type;
|
||||
public String url;
|
||||
}
|
||||
|
||||
public class TagInfo {
|
||||
public String tag;
|
||||
public String version;
|
||||
public URLType type;
|
||||
public String url;
|
||||
}
|
||||
public class TagInfo {
|
||||
public String tag;
|
||||
public String version;
|
||||
public URLType type;
|
||||
public String url;
|
||||
}
|
||||
|
||||
public enum URLType {
|
||||
Maven,
|
||||
DirectUrl;
|
||||
}
|
||||
public enum URLType {
|
||||
Maven,
|
||||
DirectUrl;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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.utils.IOUtil;
|
||||
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 {
|
||||
org.bukkit.plugin.Plugin main;
|
||||
RepoCache repocache;
|
||||
PluginHelperLogger logger = PluginHelperLogger.getLogger();
|
||||
org.bukkit.plugin.Plugin main;
|
||||
RepoCache repocache;
|
||||
|
||||
public RepositoryManager(final org.bukkit.plugin.Plugin plugin) {
|
||||
this.main = plugin;
|
||||
repocache = new RepoCache();
|
||||
}
|
||||
public RepositoryManager(final org.bukkit.plugin.Plugin plugin) {
|
||||
this.main = plugin;
|
||||
repocache = new RepoCache();
|
||||
}
|
||||
|
||||
public boolean addPackage(final CommandSender sender, final String urlstring) {
|
||||
final String json = IOUtil.getData(urlstring);
|
||||
if (json == null || json.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final PackageInfo pkg = jsonToPackage(json);
|
||||
if (pkg == null) {
|
||||
return false;
|
||||
}
|
||||
updatePackage(sender, pkg);
|
||||
return true;
|
||||
}
|
||||
public boolean addPackage(final CommandSender sender, final String urlstring) {
|
||||
final String json = IOUtil.getData(urlstring);
|
||||
if (json == null || json.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final PackageInfo pkg = jsonToPackage(json);
|
||||
if (pkg == null) {
|
||||
return false;
|
||||
}
|
||||
updatePackage(sender, pkg);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addRepositories(final CommandSender sender, final String urlstring) {
|
||||
final String url = handerRepoUrl(urlstring);
|
||||
final Repositories repo = repocache.addRepo(url);
|
||||
if (repo == null) {
|
||||
return false;
|
||||
}
|
||||
return updateRepositories(sender, repo);
|
||||
}
|
||||
public boolean addRepositories(final CommandSender sender, final String urlstring) {
|
||||
final String url = handerRepoUrl(urlstring);
|
||||
final Repositories repo = repocache.addRepo(url);
|
||||
if (repo == null) {
|
||||
return false;
|
||||
}
|
||||
return updateRepositories(sender, repo);
|
||||
}
|
||||
|
||||
public void cacheToJson(final FileConfig config) {
|
||||
config.set("reposcache", repocache.toString());
|
||||
config.save();
|
||||
}
|
||||
public void clean() {
|
||||
repocache.getPlugins().clear();
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
repocache.getPlugins().clear();
|
||||
}
|
||||
public boolean delRepositories(final CommandSender sender, final String urlstring) {
|
||||
return repocache.removeRepo(handerRepoUrl(urlstring));
|
||||
}
|
||||
|
||||
public boolean delRepositories(final CommandSender sender, final String urlstring) {
|
||||
return repocache.removeRepo(handerRepoUrl(urlstring));
|
||||
}
|
||||
public List<PluginInfo> getAllPlugin() {
|
||||
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() {
|
||||
final List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
li.add(plugin.getValue());
|
||||
}
|
||||
return li;
|
||||
}
|
||||
public List<String> getAllPluginName() {
|
||||
final List<String> li = new ArrayList<String>();
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
li.add(plugin.getValue().name);
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<String> getAllPluginName() {
|
||||
final List<String> li = new ArrayList<String>();
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
li.add(plugin.getValue().name);
|
||||
}
|
||||
return li;
|
||||
}
|
||||
public List<String> getAllPluginsInfo() {
|
||||
final List<String> li = new ArrayList<String>();
|
||||
li.add("§d仓库名称 §a插件名称 §e插件描述");
|
||||
for (final Entry<String, PluginInfo> pi : repocache.getPlugins().entrySet()) {
|
||||
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) {
|
||||
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() {
|
||||
final List<String> li = new ArrayList<String>();
|
||||
li.add("§d仓库名称 §a插件名称 §e插件描述");
|
||||
for (final Entry<String, PluginInfo> pi : repocache.getPlugins().entrySet()) {
|
||||
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) {
|
||||
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) {
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
if (plugin.getValue().name.equalsIgnoreCase(name)) {
|
||||
return plugin.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PluginInfo getPlugin(final String name) {
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
if (plugin.getValue().name.equalsIgnoreCase(name)) {
|
||||
return plugin.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public List<PluginInfo> getPluginInfo(final String name) {
|
||||
final List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
|
||||
if (plugin.getValue().name.equalsIgnoreCase(name)) {
|
||||
li.add(plugin.getValue());
|
||||
}
|
||||
}
|
||||
return li;
|
||||
}
|
||||
|
||||
public List<PluginInfo> getPluginInfo(final String name) {
|
||||
final List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
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) {
|
||||
return repocache.getPlugins().get(groupId + "." + artifactId);
|
||||
}
|
||||
|
||||
public PluginInfo getPluginInfo(final String groupId, final String artifactId) {
|
||||
return repocache.getPlugins().get(groupId + "." + artifactId);
|
||||
}
|
||||
public Map<String, PluginInfo> getPlugins() {
|
||||
return repocache.getPlugins();
|
||||
}
|
||||
|
||||
public Map<String, PluginInfo> getPlugins() {
|
||||
return repocache.getPlugins();
|
||||
}
|
||||
public RepoCache getRepoCache() {
|
||||
return repocache;
|
||||
}
|
||||
|
||||
public RepoCache getRepoCache() {
|
||||
return repocache;
|
||||
}
|
||||
public Repositories getRepoCache(final String urlstring) {
|
||||
return repocache.repos.get(handerRepoUrl(urlstring));
|
||||
}
|
||||
|
||||
public Repositories getRepoCache(final String urlstring) {
|
||||
return repocache.repos.get(handerRepoUrl(urlstring));
|
||||
}
|
||||
public Map<String, Repositories> getRepos() {
|
||||
return repocache.getRepos();
|
||||
}
|
||||
|
||||
public Map<String, Repositories> getRepos() {
|
||||
return repocache.getRepos();
|
||||
}
|
||||
public boolean getRepositories(final CommandSender sender, final String urlstring) {
|
||||
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) {
|
||||
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 PackageInfo jsonToPackage(final String json) {
|
||||
try {
|
||||
return JsonHandle.fromJson(json, PackageInfo.class);
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean jsonToCache(final FileConfiguration config) {
|
||||
try {
|
||||
final String reposcache = config.getString("reposcache");
|
||||
if (reposcache != null && !reposcache.isEmpty()) {
|
||||
repocache = RepoCache.fromJson(reposcache);
|
||||
return true;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Repositories jsonToRepositories(final String json) {
|
||||
return JsonHandle.fromJson(json, Repositories.class);
|
||||
}
|
||||
|
||||
public PackageInfo jsonToPackage(final String json) {
|
||||
try {
|
||||
return JsonHandle.fromJson(json, PackageInfo.class);
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void updatePackage(final CommandSender sender, final PackageInfo pkg) {
|
||||
for (final Plugin plugin : pkg.plugins) {
|
||||
final PluginInfo pi = new PluginInfo();
|
||||
pi.name = StringUtil.getNotNull(plugin.name, plugin.artifactId);
|
||||
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) {
|
||||
return JsonHandle.fromJson(json, Repositories.class);
|
||||
}
|
||||
public boolean updateRepositories(final CommandSender sender) {
|
||||
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) {
|
||||
for (final Plugin plugin : pkg.plugins) {
|
||||
final PluginInfo pi = new PluginInfo();
|
||||
pi.name = StringUtil.getNotNull(plugin.name, plugin.artifactId);
|
||||
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 boolean updateRepositories(CommandSender sender, final Repositories repocenter) {
|
||||
if (sender == null) {
|
||||
sender = Bukkit.getConsoleSender();
|
||||
}
|
||||
if (repocenter == null || repocenter.repos.isEmpty()) {
|
||||
logger.debug("源地址为Null或源列表为空!");
|
||||
return false;
|
||||
}
|
||||
for (final Repository repo : repocenter.repos) {
|
||||
addPackage(sender, repo.url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateRepositories(final CommandSender sender) {
|
||||
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 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user