mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 22:38:46 +00:00
大版本更新 支持一键更新老版本插件...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
857cda6fe5
commit
6e766313d6
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cn.citycraft</groupId>
|
<groupId>cn.citycraft</groupId>
|
||||||
<artifactId>Yum</artifactId>
|
<artifactId>Yum</artifactId>
|
||||||
<version>1.8.3</version>
|
<version>1.8.5</version>
|
||||||
<name>Yum</name>
|
<name>Yum</name>
|
||||||
<description>Minecraft 服务器插件管理系统</description>
|
<description>Minecraft 服务器插件管理系统</description>
|
||||||
<build>
|
<build>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</build>
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||||
<update.description>&b默认使用国内源数据 添加仓库查看命令...</update.description>
|
<update.description>&c重大更新 支持一键更新老版本插件...</update.description>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
||||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||||
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
import cn.citycraft.Yum.commands.CommandDelete;
|
import cn.citycraft.Yum.commands.CommandDelete;
|
||||||
import cn.citycraft.Yum.commands.CommandInfo;
|
import cn.citycraft.Yum.commands.CommandInfo;
|
||||||
import cn.citycraft.Yum.commands.CommandInstall;
|
import cn.citycraft.Yum.commands.CommandInstall;
|
||||||
@ -19,7 +20,6 @@ import cn.citycraft.Yum.commands.CommandUnload;
|
|||||||
import cn.citycraft.Yum.commands.CommandUpdate;
|
import cn.citycraft.Yum.commands.CommandUpdate;
|
||||||
import cn.citycraft.Yum.commands.CommandUpdateAll;
|
import cn.citycraft.Yum.commands.CommandUpdateAll;
|
||||||
import cn.citycraft.Yum.commands.CommandUpgrade;
|
import cn.citycraft.Yum.commands.CommandUpgrade;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MC插件仓库
|
* MC插件仓库
|
||||||
@ -28,7 +28,7 @@ import cn.citycraft.Yum.manager.YumManager;
|
|||||||
*/
|
*/
|
||||||
public class Yum extends JavaPlugin {
|
public class Yum extends JavaPlugin {
|
||||||
public FileConfig config;
|
public FileConfig config;
|
||||||
public YumManager yumgr;
|
public YumAPI yumgr;
|
||||||
|
|
||||||
public void initCommands() {
|
public void initCommands() {
|
||||||
final HandlerSubCommand cmdhandler = new HandlerSubCommand(this, "yum");
|
final HandlerSubCommand cmdhandler = new HandlerSubCommand(this, "yum");
|
||||||
@ -47,16 +47,16 @@ public class Yum extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
YumManager.repo.cacheToJson(config);
|
YumAPI.repo.cacheToJson(config);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.initCommands();
|
this.initCommands();
|
||||||
yumgr = new YumManager(this);
|
yumgr = new YumAPI(this);
|
||||||
YumManager.repo.jsonToCache(config);
|
YumAPI.repo.jsonToCache(config);
|
||||||
YumManager.updaterepo();
|
YumAPI.updaterepo();
|
||||||
new VersionChecker(this);
|
new VersionChecker(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
250
src/main/java/cn/citycraft/Yum/api/YumAPI.java
Normal file
250
src/main/java/cn/citycraft/Yum/api/YumAPI.java
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
package cn.citycraft.Yum.api;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import cn.citycraft.CommonData.UpdatePlugin;
|
||||||
|
import cn.citycraft.Yum.manager.DownloadManager;
|
||||||
|
import cn.citycraft.Yum.manager.PluginInfo;
|
||||||
|
import cn.citycraft.Yum.manager.PluginsManager;
|
||||||
|
import cn.citycraft.Yum.manager.RepositoryManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Yum管理中心
|
||||||
|
*
|
||||||
|
* @author 蒋天蓓
|
||||||
|
* 2015年9月1日上午10:59:47
|
||||||
|
*/
|
||||||
|
public class YumAPI {
|
||||||
|
public static DownloadManager download;
|
||||||
|
public static PluginsManager plugman;
|
||||||
|
public static RepositoryManager repo;
|
||||||
|
|
||||||
|
protected static Plugin main;
|
||||||
|
|
||||||
|
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 sender
|
||||||
|
* - 命令发送者
|
||||||
|
* @param pluginname
|
||||||
|
* - 插件名称
|
||||||
|
* @param version
|
||||||
|
* - 插件版本
|
||||||
|
* @return 是否安装成功
|
||||||
|
*/
|
||||||
|
public static boolean install(final CommandSender sender, final String pluginname, final String url) {
|
||||||
|
if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar"))) {
|
||||||
|
return plugman.load(sender, pluginname);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安装新插件
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* - 插件名称
|
||||||
|
* @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.getMavenUrl(sender, version));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 载入插件
|
||||||
|
*
|
||||||
|
* @param pluginname
|
||||||
|
* - 插件名称
|
||||||
|
*/
|
||||||
|
public static void load(final String pluginname) {
|
||||||
|
plugman.load(pluginname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卸载插件
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
* - 插件实体
|
||||||
|
*/
|
||||||
|
public static void reload(final Plugin plugin) {
|
||||||
|
plugman.unload(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重载插件
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
* - 插件实体
|
||||||
|
*/
|
||||||
|
public static void unload(final Plugin plugin) {
|
||||||
|
plugman.reload(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更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新插件
|
||||||
|
*
|
||||||
|
* @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 Map<Plugin, String> updatelist = UpdatePlugin.getList();
|
||||||
|
if (updatelist.size() > 0) {
|
||||||
|
for (final Entry<Plugin, String> updateplugin : UpdatePlugin.getList().entrySet()) {
|
||||||
|
updatefromyum(sender, updateplugin.getKey(), updateplugin.getValue());
|
||||||
|
}
|
||||||
|
UpdatePlugin.getList().clear();
|
||||||
|
sender.sendMessage("§6更新: §c已下载所有需要插件的插件到 到update文件夹 重启后自动更新(或使用/yum upgrade直接升级)!");
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从Yum内部更新插件
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* - 命令发送者
|
||||||
|
* @param plugin
|
||||||
|
* - 插件实体
|
||||||
|
* @param version
|
||||||
|
* - 插件版本(null则自动获取)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
|
||||||
|
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||||
|
if (pi != null) {
|
||||||
|
if (download.run(sender, pi.getMavenUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
||||||
|
sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package cn.citycraft.Yum.api;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Yum仓库插件API
|
|
||||||
*
|
|
||||||
* @author 蒋天蓓
|
|
||||||
* @since 2015年8月22日下午4:43:41
|
|
||||||
*/
|
|
||||||
public class YumApi {
|
|
||||||
public static boolean update(final CommandSender sender, final Plugin plugin, final URL url, final String version) {
|
|
||||||
return YumManager.update(sender, plugin, url, version);
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件删除命令类
|
* 插件删除命令类
|
||||||
@ -37,7 +37,7 @@ public class CommandDelete extends BaseCommand {
|
|||||||
final String pluginname = args[0];
|
final String pluginname = args[0];
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
if (YumManager.plugman.deletePlugin(sender, plugin)) {
|
if (YumAPI.plugman.deletePlugin(sender, plugin)) {
|
||||||
sender.sendMessage("§c删除: §a插件 " + pluginname + " 已从服务器卸载并删除!");
|
sender.sendMessage("§c删除: §a插件 " + pluginname + " 已从服务器卸载并删除!");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
|
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
|
||||||
|
@ -16,7 +16,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.PluginHelper.utils.StringUtil;
|
import cn.citycraft.PluginHelper.utils.StringUtil;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件删除命令类
|
* 插件删除命令类
|
||||||
@ -51,7 +51,7 @@ public class CommandInfo extends BaseCommand {
|
|||||||
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
|
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
|
||||||
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "无" : ""));
|
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "无" : ""));
|
||||||
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
|
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
|
||||||
sender.sendMessage("§6插件物理路径: §3" + YumManager.plugman.getPluginFile(plugin).getAbsolutePath());
|
sender.sendMessage("§6插件物理路径: §3" + YumAPI.plugman.getPluginFile(plugin).getAbsolutePath());
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ public class CommandInfo extends BaseCommand {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) {
|
if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) {
|
||||||
return StringUtil.copyPartialMatches(args[1], YumManager.plugman.getPluginNames(false), new ArrayList<String>());
|
return StringUtil.copyPartialMatches(args[1], YumAPI.plugman.getPluginNames(false), new ArrayList<String>());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.PluginHelper.utils.StringUtil;
|
import cn.citycraft.PluginHelper.utils.StringUtil;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件安装命令类
|
* 插件安装命令类
|
||||||
@ -45,9 +45,9 @@ public class CommandInstall extends BaseCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
YumManager.install(sender, pluginname);
|
YumAPI.installfromyum(sender, pluginname);
|
||||||
} else {
|
} else {
|
||||||
YumManager.install(sender, pluginname, args[1]);
|
YumAPI.installfromyum(sender, pluginname, args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -59,7 +59,7 @@ public class CommandInstall extends BaseCommand {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
if (args[0].equalsIgnoreCase("install")) {
|
if (args[0].equalsIgnoreCase("install")) {
|
||||||
return StringUtil.copyPartialMatches(args[1], YumManager.repo.getAllPluginName(), new ArrayList<String>());
|
return StringUtil.copyPartialMatches(args[1], YumAPI.repo.getAllPluginName(), new ArrayList<String>());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件查看命令类
|
* 插件查看命令类
|
||||||
@ -34,7 +34,7 @@ public class CommandList extends BaseCommand {
|
|||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
sender.sendMessage("§6 - " + YumManager.plugman.getFormattedName(plugin, true));
|
sender.sendMessage("§6 - " + YumAPI.plugman.getFormattedName(plugin, true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件删除命令类
|
* 插件删除命令类
|
||||||
@ -37,7 +37,7 @@ public class CommandLoad extends BaseCommand {
|
|||||||
final String pluginname = args[0];
|
final String pluginname = args[0];
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
YumManager.plugman.load(sender, pluginname);
|
YumAPI.plugman.load(sender, pluginname);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件删除命令类
|
* 插件删除命令类
|
||||||
@ -36,12 +36,12 @@ public class CommandReload extends BaseCommand {
|
|||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final String pluginname = args[0];
|
final String pluginname = args[0];
|
||||||
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
|
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
|
||||||
YumManager.plugman.reloadAll(sender);
|
YumAPI.plugman.reloadAll(sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
YumManager.plugman.reload(sender, plugin);
|
YumAPI.plugman.reload(sender, plugin);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.PluginHelper.utils.StringUtil;
|
import cn.citycraft.PluginHelper.utils.StringUtil;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件删除命令类
|
* 插件删除命令类
|
||||||
@ -44,8 +44,8 @@ public class CommandRepo extends BaseCommand {
|
|||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case "add":
|
case "add":
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
if (YumManager.repo.addRepositories(sender, args[1])) {
|
if (YumAPI.repo.addRepositories(sender, args[1])) {
|
||||||
final String reponame = YumManager.repo.getRepoCache(args[1]).name;
|
final String reponame = YumAPI.repo.getRepoCache(args[1]).name;
|
||||||
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
|
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
|
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
|
||||||
@ -56,8 +56,8 @@ public class CommandRepo extends BaseCommand {
|
|||||||
break;
|
break;
|
||||||
case "del":
|
case "del":
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
if (YumManager.repo.delRepositories(sender, args[1])) {
|
if (YumAPI.repo.delRepositories(sender, args[1])) {
|
||||||
final String reponame = YumManager.repo.getRepoCache(args[1]).name;
|
final String reponame = YumAPI.repo.getRepoCache(args[1]).name;
|
||||||
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
|
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§6仓库: §c源地址未找到!");
|
sender.sendMessage("§6仓库: §c源地址未找到!");
|
||||||
@ -68,18 +68,18 @@ public class CommandRepo extends BaseCommand {
|
|||||||
break;
|
break;
|
||||||
case "list":
|
case "list":
|
||||||
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
||||||
StringUtil.sendStringArray(sender, YumManager.repo.getAllPluginsInfo());
|
StringUtil.sendStringArray(sender, YumAPI.repo.getAllPluginsInfo());
|
||||||
break;
|
break;
|
||||||
case "all":
|
case "all":
|
||||||
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
|
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
|
||||||
StringUtil.sendStringArray(sender, YumManager.repo.getRepoCache().getAllRepoInfo());
|
StringUtil.sendStringArray(sender, YumAPI.repo.getRepoCache().getAllRepoInfo());
|
||||||
break;
|
break;
|
||||||
case "clean":
|
case "clean":
|
||||||
YumManager.repo.clean();
|
YumAPI.repo.clean();
|
||||||
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
||||||
break;
|
break;
|
||||||
case "update":
|
case "update":
|
||||||
YumManager.repo.updateRepositories(sender);
|
YumAPI.repo.updateRepositories(sender);
|
||||||
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ public class CommandRepo extends BaseCommand {
|
|||||||
return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "clean", "update", "del" }), new ArrayList<String>());
|
return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "clean", "update", "del" }), new ArrayList<String>());
|
||||||
}
|
}
|
||||||
if (args.length == 3 && (args[1] == "add" || args[1] == "del")) {
|
if (args.length == 3 && (args[1] == "add" || args[1] == "del")) {
|
||||||
return StringUtil.copyPartialMatches(args[2], YumManager.repo.getRepos().keySet(), new ArrayList<String>());
|
return StringUtil.copyPartialMatches(args[2], YumAPI.repo.getRepos().keySet(), new ArrayList<String>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件删除命令类
|
* 插件删除命令类
|
||||||
@ -37,7 +37,7 @@ public class CommandUnload extends BaseCommand {
|
|||||||
final String pluginname = args[0];
|
final String pluginname = args[0];
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
YumManager.plugman.unload(sender, plugin);
|
YumAPI.plugman.unload(sender, plugin);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||||
@ -40,9 +40,9 @@ public class CommandUpdate extends BaseCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
YumManager.update(sender, plugin);
|
YumAPI.updatefromyum(sender, plugin);
|
||||||
} else {
|
} else {
|
||||||
YumManager.update(sender, plugin, args[1]);
|
YumAPI.updatefromyum(sender, plugin, args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -7,11 +7,10 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandException;
|
import org.bukkit.command.CommandException;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||||
@ -30,22 +29,12 @@ public class CommandUpdateAll extends BaseCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||||
final String pluginname = args[0];
|
sender.sendMessage("§d开始更新服务器可更新插件");
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
|
||||||
sender.sendMessage("§a开始更新服务器可更新插件");
|
|
||||||
if (plugin != null) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length < 2) {
|
YumAPI.updateall(sender);
|
||||||
YumManager.update(sender, plugin);
|
|
||||||
} else {
|
|
||||||
YumManager.update(sender, plugin, args[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
import cn.citycraft.Yum.manager.YumManager;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||||
@ -35,13 +35,13 @@ public class CommandUpgrade extends BaseCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
YumManager.plugman.upgrade(sender);
|
YumAPI.plugman.upgrade(sender);
|
||||||
} else {
|
} else {
|
||||||
final String pluginname = args[0];
|
final String pluginname = args[0];
|
||||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||||
sender.sendMessage("§a开始升级插件: " + pluginname);
|
sender.sendMessage("§a开始升级插件: " + pluginname);
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
YumManager.plugman.upgrade(sender, plugin);
|
YumAPI.upgrade(sender, plugin);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,15 @@ public class PluginInfo {
|
|||||||
return String.format("%1$s-%2$s.jar", plugin.artifactId, version);
|
return String.format("%1$s-%2$s.jar", plugin.artifactId, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Maven仓库指定插件的下载地址
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* - 命令发送者
|
||||||
|
* @param version
|
||||||
|
* - 需要更新的版本
|
||||||
|
* @return 更新地址
|
||||||
|
*/
|
||||||
public String getMavenUrl(final CommandSender sender, final String version) {
|
public String getMavenUrl(final CommandSender sender, final String version) {
|
||||||
String ver = version;
|
String ver = version;
|
||||||
if (ver == null) {
|
if (ver == null) {
|
||||||
|
@ -363,7 +363,7 @@ public class PluginsManager {
|
|||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* - 命令发送者
|
||||||
* @param plugin
|
* @param main
|
||||||
* - 插件
|
* - 插件
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
package cn.citycraft.Yum.manager;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动更新类
|
|
||||||
*
|
|
||||||
* @author 蒋天蓓
|
|
||||||
* 2015年9月1日上午10:59:47
|
|
||||||
*/
|
|
||||||
public class YumManager {
|
|
||||||
public static DownloadManager download;
|
|
||||||
public static PluginsManager plugman;
|
|
||||||
public static RepositoryManager repo;
|
|
||||||
|
|
||||||
protected static Plugin plugin;
|
|
||||||
|
|
||||||
public YumManager(final Plugin plugin) {
|
|
||||||
YumManager.plugin = plugin;
|
|
||||||
plugman = new PluginsManager(plugin);
|
|
||||||
download = new DownloadManager(plugin);
|
|
||||||
repo = new RepositoryManager(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean install(final CommandSender sender, final String pluginname) {
|
|
||||||
return install(sender, pluginname, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean install(final CommandSender sender, final String pluginname, final String version) {
|
|
||||||
final PluginInfo pi = repo.getPlugin(pluginname);
|
|
||||||
if (pi != null) {
|
|
||||||
if (download.run(sender, pi.getMavenUrl(sender, version), new File("plugins", pi.name + ".jar"))) {
|
|
||||||
return plugman.load(sender, pluginname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean update(final CommandSender sender, final Plugin plugin) {
|
|
||||||
return update(sender, plugin, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean update(final CommandSender sender, final Plugin plugin, final String version) {
|
|
||||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
|
||||||
if (pi != null) {
|
|
||||||
if (download.run(sender, pi.getMavenUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
|
||||||
sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean update(final CommandSender sender, final Plugin plugin, final URL url, final String version) {
|
|
||||||
if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
|
||||||
sender.sendMessage("§6更新: §a已下载插件 " + plugin.getName() + " 到update文件夹 重启后自动更新(或使用upgrade直接升级)!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updaterepo() {
|
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
repo.updateRepositories(Bukkit.getConsoleSender());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user