添加部分API...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-11-27 16:43:32 +08:00
parent ab14c50c36
commit 0bf5cd6a8b
2 changed files with 78 additions and 37 deletions

View File

@ -24,12 +24,18 @@ import cn.citycraft.Yum.manager.RepositoryManager;
public class YumAPI { public class YumAPI {
private static DownloadManager download; private static DownloadManager download;
private static Plugin main;
private static PluginsManager plugman; private static PluginsManager plugman;
private static RepositoryManager repo; private static RepositoryManager repo;
protected static Plugin main; /**
* 初始化Yum管理中心
*
* @param plugin
* - 插件实体
*/
public YumAPI(final Plugin plugin) { public YumAPI(final Plugin plugin) {
YumAPI.main = plugin; YumAPI.main = plugin;
plugman = new PluginsManager(main); plugman = new PluginsManager(main);
@ -86,8 +92,9 @@ public class YumAPI {
* @return 是否安装成功 * @return 是否安装成功
*/ */
public static boolean install(final CommandSender sender, final String pluginname, final String url) { public static boolean install(final CommandSender sender, final String pluginname, final String url) {
if (download.run(sender, url, new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar"))) { final File pluginFile = new File(Bukkit.getUpdateFolderFile().getParentFile(), pluginname + ".jar");
return plugman.load(sender, pluginname); if (download.run(sender, url, pluginFile)) {
return plugman.load(sender, pluginFile);
} }
return false; return false;
} }
@ -143,18 +150,18 @@ public class YumAPI {
* @param pluginname * @param pluginname
* - 插件名称 * - 插件名称
*/ */
public static void load(final String pluginname) { public static void load(final File pluginFile) {
plugman.load(pluginname); plugman.load(pluginFile);
} }
/** /**
* 载插件 * 插件
* *
* @param plugin * @param pluginname
* - 插件实体 * - 插件名称
*/ */
public static void reload(final Plugin plugin) { public static void load(final String pluginname) {
plugman.unload(plugin); plugman.load(pluginname);
} }
/** /**
@ -163,10 +170,20 @@ public class YumAPI {
* @param plugin * @param plugin
* - 插件实体 * - 插件实体
*/ */
public static void unload(final Plugin plugin) { public static void reload(final Plugin plugin) {
plugman.reload(plugin); plugman.reload(plugin);
} }
/**
* 卸载插件
*
* @param plugin
* - 插件实体
*/
public static void unload(final Plugin plugin) {
plugman.unload(plugin);
}
/** /**
* 更新插件 * 更新插件
* *

View File

@ -258,6 +258,44 @@ public class PluginsManager {
return false; return false;
} }
/**
* 载入插件
*
* @param sender
* - 命令发送者
* @param pluginFile
* - 插件文件
* @return 是否成功
*/
public boolean load(final CommandSender sender, final File pluginFile) {
Plugin target = null;
final String name = pluginFile.getName();
try {
target = Bukkit.getPluginManager().loadPlugin(pluginFile);
} catch (final InvalidDescriptionException e) {
sender.sendMessage("§4异常: §c" + e.getMessage());
sender.sendMessage("§c插件: " + name + " 的 plugin.yml 文件存在错误!");
return false;
} catch (final UnsupportedClassVersionError e) {
sender.sendMessage("§4异常: §c" + e.getMessage());
sender.sendMessage("§c服务器或JAVA的版本低于插件: " + name + " 所需要的版本!!");
return false;
} catch (final InvalidPluginException e) {
sender.sendMessage("§4异常: §c" + e.getMessage());
sender.sendMessage("§c文件: " + name + " 不是一个可载入的插件!");
return false;
} catch (final UnknownDependencyException e) {
sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage());
sender.sendMessage("§c插件: " + name + " 载入失败 缺少部分依赖项目!");
return false;
}
target.onLoad();
Bukkit.getPluginManager().enablePlugin(target);
sender.sendMessage("§6载入: §a插件 " + name + " 已成功载入到服务器!");
return true;
}
/** /**
* 载入插件 * 载入插件
* *
@ -268,7 +306,6 @@ public class PluginsManager {
* @return 是否成功 * @return 是否成功
*/ */
public boolean load(CommandSender sender, final String name) { public boolean load(CommandSender sender, final String name) {
Plugin target = null;
String filename = null; String filename = null;
if (sender == null) { if (sender == null) {
sender = Bukkit.getConsoleSender(); sender = Bukkit.getConsoleSender();
@ -304,31 +341,18 @@ public class PluginsManager {
return false; return false;
} }
} }
return load(sender, pluginFile);
try {
target = Bukkit.getPluginManager().loadPlugin(pluginFile);
} catch (final InvalidDescriptionException e) {
sender.sendMessage("§4异常: §c" + e.getMessage());
sender.sendMessage("§c插件: " + name + " 的 plugin.yml 文件存在错误!");
return false;
} catch (final UnsupportedClassVersionError e) {
sender.sendMessage("§4异常: §c" + e.getMessage());
sender.sendMessage("§c服务器或JAVA的版本低于插件: " + name + " 所需要的版本!!");
return false;
} catch (final InvalidPluginException e) {
sender.sendMessage("§4异常: §c" + e.getMessage());
sender.sendMessage("§c文件: " + name + " 不是一个可载入的插件!");
return false;
} catch (final UnknownDependencyException e) {
sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage());
sender.sendMessage("§c插件: " + name + " 载入失败 缺少部分依赖项目!");
return false;
} }
target.onLoad(); /**
Bukkit.getPluginManager().enablePlugin(target); * 载入插件
sender.sendMessage("§6载入: §a插件 " + name + " 已成功载入到服务器!"); *
return true; * @param pluginFile
* - 插件名称
* @return 是否成功
*/
public boolean load(final File pluginFile) {
return load(Bukkit.getConsoleSender(), pluginFile);
} }
/** /**