mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 06:18:46 +00:00
add yummanager and modify plugininfo...
This commit is contained in:
parent
8f8e3b3465
commit
8107333391
@ -7,9 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.Yum.commands.CommandHandler;
|
||||
import cn.citycraft.Yum.config.FileConfig;
|
||||
import cn.citycraft.Yum.manager.DownloadManager;
|
||||
import cn.citycraft.Yum.manager.PluginsManager;
|
||||
import cn.citycraft.Yum.repository.RepositoryManager;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* MC插件仓库
|
||||
@ -17,9 +15,7 @@ import cn.citycraft.Yum.repository.RepositoryManager;
|
||||
* @author 蒋天蓓 2015年8月21日下午5:14:39
|
||||
*/
|
||||
public class Yum extends JavaPlugin {
|
||||
public DownloadManager download;
|
||||
public PluginsManager plugman;
|
||||
public RepositoryManager repo;
|
||||
public YumManager yumgr;
|
||||
public FileConfig config;
|
||||
|
||||
@Override
|
||||
@ -32,16 +28,13 @@ public class Yum extends JavaPlugin {
|
||||
CommandHandler cmdhandler = new CommandHandler(this);
|
||||
this.getCommand("yum").setExecutor(cmdhandler);
|
||||
this.getCommand("yum").setTabCompleter(cmdhandler);
|
||||
|
||||
plugman = new PluginsManager(this);
|
||||
download = new DownloadManager(this);
|
||||
repo = new RepositoryManager(this);
|
||||
repo.jsonToCache(config);
|
||||
yumgr = new YumManager(this);
|
||||
YumManager.repo.jsonToCache(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
repo.cacheToJson(config);
|
||||
YumManager.repo.cacheToJson(config);
|
||||
config.save();
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* 插件删除命令类
|
||||
@ -31,7 +32,7 @@ public class CommandDelete extends BaseCommand {
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
main.plugman.deletePlugin(sender, plugin);
|
||||
YumManager.plugman.deletePlugin(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* 子命令处理类
|
||||
@ -131,7 +132,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
String partialPlugin = args[1];
|
||||
List<String> plugins = null;
|
||||
if (args[0].equalsIgnoreCase("install"))
|
||||
plugins = main.repo.getAllPluginName();
|
||||
plugins = YumManager.repo.getAllPluginName();
|
||||
else if (args[0].equalsIgnoreCase("repo"))
|
||||
plugins = Arrays.asList(new String[] {
|
||||
"add",
|
||||
@ -140,7 +141,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
"update"
|
||||
});
|
||||
else
|
||||
plugins = main.plugman.getPluginNames(false);
|
||||
plugins = YumManager.plugman.getPluginNames(false);
|
||||
StringUtil.copyPartialMatches(partialPlugin, plugins, completions);
|
||||
}
|
||||
Collections.sort(completions);
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
import cn.citycraft.Yum.utils.StringUtil;
|
||||
|
||||
/**
|
||||
@ -50,7 +51,7 @@ public class CommandInfo extends BaseCommand {
|
||||
StringUtil.sendStringArray(sender, desc.getDepend());
|
||||
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, desc.getSoftDepend());
|
||||
sender.sendMessage("§6插件物理路径: §3" + main.plugman.getPluginFile(plugin).getAbsolutePath());
|
||||
sender.sendMessage("§6插件物理路径: §3" + YumManager.plugman.getPluginFile(plugin).getAbsolutePath());
|
||||
} else {
|
||||
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.repository.PluginInfo;
|
||||
|
||||
/**
|
||||
* 插件安装命令类
|
||||
@ -35,11 +34,7 @@ public class CommandInstall extends BaseCommand {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PluginInfo pi = main.repo.getPlugin(pluginname);
|
||||
if (pi != null)
|
||||
if (main.download.run(sender, pi.getMavenUrl())) {
|
||||
main.plugman.load(sender, pluginname);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* 插件查看命令类
|
||||
@ -35,7 +36,7 @@ public class CommandList extends BaseCommand {
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
sender.sendMessage("§6 - " + main.plugman.getFormattedName(plugin, true));
|
||||
sender.sendMessage("§6 - " + YumManager.plugman.getFormattedName(plugin, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* 插件删除命令类
|
||||
@ -31,7 +32,7 @@ public class CommandLoad extends BaseCommand {
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin == null) {
|
||||
main.plugman.load(sender, pluginname);
|
||||
YumManager.plugman.load(sender, pluginname);
|
||||
} else {
|
||||
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* 插件删除命令类
|
||||
@ -30,12 +31,12 @@ public class CommandReload extends BaseCommand {
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
String pluginname = args[0];
|
||||
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
|
||||
main.plugman.reloadAll(sender);
|
||||
YumManager.plugman.reloadAll(sender);
|
||||
return;
|
||||
}
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
main.plugman.reload(sender, plugin);
|
||||
YumManager.plugman.reload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
import cn.citycraft.Yum.utils.StringUtil;
|
||||
|
||||
/**
|
||||
@ -31,7 +32,7 @@ public class CommandRepo extends BaseCommand {
|
||||
switch (cmd) {
|
||||
case "add":
|
||||
if (args.length == 2) {
|
||||
if (main.repo.addRepositories(args[1])) {
|
||||
if (YumManager.repo.addRepositories(args[1])) {
|
||||
sender.sendMessage("§6仓库: §a插件信息已缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或无法访问!");
|
||||
@ -42,14 +43,14 @@ public class CommandRepo extends BaseCommand {
|
||||
break;
|
||||
case "list":
|
||||
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
||||
StringUtil.sendStringArray(sender, main.repo.getAllPluginsInfo());
|
||||
StringUtil.sendStringArray(sender, YumManager.repo.getAllPluginsInfo());
|
||||
break;
|
||||
case "clean":
|
||||
main.repo.clean();
|
||||
YumManager.repo.clean();
|
||||
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
||||
break;
|
||||
case "update":
|
||||
main.repo.updateRepositories(sender);
|
||||
YumManager.repo.updateRepositories(sender);
|
||||
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
||||
break;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* 插件删除命令类
|
||||
@ -31,7 +32,7 @@ public class CommandUnload extends BaseCommand {
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
main.plugman.unload(sender, plugin);
|
||||
YumManager.plugman.unload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.repository.PluginInfo;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
|
||||
/**
|
||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||
@ -34,21 +34,10 @@ public class CommandUpdate extends BaseCommand {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PluginInfo pi = main.repo.getPlugin(pluginname);
|
||||
if (pi != null) {
|
||||
String fileurl;
|
||||
if (args.length < 2) {
|
||||
fileurl = pi.getMavenUrl();
|
||||
} else {
|
||||
fileurl = pi.getMavenUrl(args[1]);
|
||||
}
|
||||
if (main.download.run(sender, fileurl, main.plugman.getPluginFile(plugin))) {
|
||||
if (main.plugman.unload(sender, plugin)) {
|
||||
main.plugman.load(sender, pluginname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
YumManager.update(sender, plugin);
|
||||
else
|
||||
YumManager.update(sender, plugin, args[1]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -1,34 +0,0 @@
|
||||
package cn.citycraft.Yum.manager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* 自动更新类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年9月1日上午10:59:47
|
||||
*/
|
||||
public class AutoUpdateManager {
|
||||
Plugin plugin;
|
||||
DownloadManager download;
|
||||
PluginsManager plugman;
|
||||
|
||||
public AutoUpdateManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
plugman = new PluginsManager(plugin);
|
||||
download = new DownloadManager(plugin);
|
||||
}
|
||||
|
||||
public boolean run(CommandSender sender) {
|
||||
if (download.run(sender, "下载地址", plugman.getPluginFile(plugin))) {
|
||||
plugman.reload(sender, plugin);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean run() {
|
||||
return run(Bukkit.getConsoleSender());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.Yum.repository;
|
||||
package cn.citycraft.Yum.manager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -15,7 +15,10 @@ import java.util.Map.Entry;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.repository.Package;
|
||||
import cn.citycraft.Yum.repository.Plugin;
|
||||
import cn.citycraft.Yum.repository.PluginInfo;
|
||||
import cn.citycraft.Yum.repository.Repository;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.gson.Gson;
|
||||
@ -32,10 +35,10 @@ public class RepositoryManager {
|
||||
List<String> repos;
|
||||
HashMap<String, PluginInfo> plugins;
|
||||
|
||||
Yum main;
|
||||
org.bukkit.plugin.Plugin main;
|
||||
|
||||
public RepositoryManager(Yum yum) {
|
||||
this.main = yum;
|
||||
public RepositoryManager(org.bukkit.plugin.Plugin plugin) {
|
||||
this.main = plugin;
|
||||
gson = new Gson();
|
||||
plugins = new HashMap<String, PluginInfo>();
|
||||
repos = new ArrayList<String>();
|
||||
@ -45,7 +48,7 @@ public class RepositoryManager {
|
||||
plugins.clear();
|
||||
}
|
||||
|
||||
public void update(Package pkg) {
|
||||
public void updatePackage(Package pkg) {
|
||||
for (Plugin plugin : pkg.plugins) {
|
||||
PluginInfo pi = new PluginInfo();
|
||||
pi.plugin = plugin;
|
||||
@ -113,7 +116,7 @@ public class RepositoryManager {
|
||||
if (pkg == null) {
|
||||
return false;
|
||||
}
|
||||
update(pkg);
|
||||
updatePackage(pkg);
|
||||
return true;
|
||||
}
|
||||
|
57
src/main/java/cn/citycraft/Yum/manager/YumManager.java
Normal file
57
src/main/java/cn/citycraft/Yum/manager/YumManager.java
Normal file
@ -0,0 +1,57 @@
|
||||
package cn.citycraft.Yum.manager;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.repository.PluginInfo;
|
||||
|
||||
/**
|
||||
* 自动更新类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年9月1日上午10:59:47
|
||||
*/
|
||||
public class YumManager {
|
||||
Plugin plugin;
|
||||
public static DownloadManager download;
|
||||
public static PluginsManager plugman;
|
||||
public static RepositoryManager repo;
|
||||
|
||||
public YumManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
plugman = new PluginsManager(plugin);
|
||||
download = new DownloadManager(plugin);
|
||||
repo = new RepositoryManager(plugin);
|
||||
}
|
||||
|
||||
public static boolean install(CommandSender sender, String pluginname) {
|
||||
return install(sender, pluginname, null);
|
||||
}
|
||||
|
||||
public static boolean install(CommandSender sender, String pluginname, String version) {
|
||||
PluginInfo pi = repo.getPlugin(pluginname);
|
||||
if (pi != null)
|
||||
if (download.run(sender, pi.getMavenUrl(version))) {
|
||||
return plugman.load(sender, pluginname);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean update(CommandSender sender, Plugin plugin) {
|
||||
return update(sender, plugin, null);
|
||||
}
|
||||
|
||||
public static boolean update(CommandSender sender, Plugin plugin, String version) {
|
||||
PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||
if (pi != null) {
|
||||
|
||||
if (download.run(sender, pi.getMavenUrl(version), plugman.getPluginFile(plugin))) {
|
||||
return plugman.reload(sender, plugin);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,13 +12,12 @@ public class PluginInfo {
|
||||
public String repo;
|
||||
|
||||
public String getMavenUrl() {
|
||||
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"),
|
||||
plugin.artifactId, plugin.version);
|
||||
return getMavenUrl(null);
|
||||
}
|
||||
|
||||
public String getMavenUrl(String version) {
|
||||
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"),
|
||||
plugin.artifactId, version);
|
||||
plugin.artifactId, version == null ? plugin.version : version);
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
|
Loading…
Reference in New Issue
Block a user