diff --git a/src/main/java/cn/citycraft/Yum/utils/PluginsManager.java b/src/main/java/cn/citycraft/Yum/utils/PluginsManager.java index 5668af8..ac6ebe8 100644 --- a/src/main/java/cn/citycraft/Yum/utils/PluginsManager.java +++ b/src/main/java/cn/citycraft/Yum/utils/PluginsManager.java @@ -62,14 +62,14 @@ public class PluginsManager { } } - public static boolean deletePlugin(Plugin plugin) { - return deletePlugin(Bukkit.getConsoleSender(), plugin); - } - public static boolean deletePlugin(CommandSender sender, Plugin plugin) { return unload(sender, plugin) && getPluginFile(plugin).delete(); } + public static boolean deletePlugin(Plugin plugin) { + return deletePlugin(Bukkit.getConsoleSender(), plugin); + } + public static void disable(Plugin plugin) { if ((plugin.isEnabled()) && (plugin != null)) { Bukkit.getPluginManager().disablePlugin(plugin); @@ -106,8 +106,7 @@ public class PluginsManager { ChatColor color = plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED; String pluginName = color + plugin.getName(); if (includeVersions) { - pluginName = pluginName + " (" - + plugin.getDescription().getVersion() + ")"; + pluginName = pluginName + " (" + plugin.getDescription().getVersion() + ")"; } return pluginName; } @@ -135,8 +134,7 @@ public class PluginsManager { public static List getPluginNames(boolean fullName) { List plugins = new ArrayList(); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - plugins.add(fullName ? plugin.getDescription().getFullName() - : plugin.getName()); + plugins.add(fullName ? plugin.getDescription().getFullName() : plugin.getName()); } return plugins; } @@ -151,15 +149,12 @@ public class PluginsManager { public static String getUsages(Plugin plugin) { List parsedCommands = new ArrayList(); - Map> commands = plugin.getDescription() - .getCommands(); + Map> commands = plugin.getDescription().getCommands(); if (commands != null) { - Iterator>> commandsIt = commands - .entrySet().iterator(); + Iterator>> commandsIt = commands.entrySet().iterator(); while (commandsIt.hasNext()) { - Entry> thisEntry = commandsIt - .next(); + Entry> thisEntry = commandsIt.next(); if (thisEntry != null) { parsedCommands.add(thisEntry.getKey()); } @@ -233,16 +228,13 @@ public class PluginsManager { try { target = Bukkit.getPluginManager().loadPlugin(pluginFile); } catch (InvalidDescriptionException e) { - sender.sendMessage("§c异常: " + e.getMessage() + " 插件: " + name - + " 的plugin.yml文件存在错误!"); + sender.sendMessage("§c异常: " + e.getMessage() + " 插件: " + name + " 的plugin.yml文件存在错误!"); return false; } catch (InvalidPluginException e) { - sender.sendMessage("§c异常: " + e.getMessage() + " 文件: " + name - + " 不是一个可载入的插件!"); + sender.sendMessage("§c异常: " + e.getMessage() + " 文件: " + name + " 不是一个可载入的插件!"); return false; } catch (UnknownDependencyException e) { - sender.sendMessage("§c异常: " + e.getMessage() + " 插件: " + name - + " 缺少部分依赖项目!"); + sender.sendMessage("§c异常: " + e.getMessage() + " 插件: " + name + " 缺少部分依赖项目!"); return false; } @@ -260,15 +252,14 @@ public class PluginsManager { return load(Bukkit.getConsoleSender(), name); } - public static boolean reload(Plugin plugin) { - return reload(Bukkit.getConsoleSender(), plugin); + public static boolean reload(CommandSender sender, Plugin plugin) { + if (plugin != null) + return unload(sender, plugin) && load(sender, plugin); + return false; } - public static boolean reload(CommandSender sender, Plugin plugin) { - if (plugin != null) { - return unload(sender, plugin) && load(sender, plugin); - } - return false; + public static boolean reload(Plugin plugin) { + return reload(Bukkit.getConsoleSender(), plugin); } public static void reloadAll() { @@ -294,41 +285,31 @@ public class PluginsManager { boolean reloadlisteners = true; if (pluginManager != null) { try { - Field pluginsField = Bukkit.getPluginManager().getClass() - .getDeclaredField("plugins"); + Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins"); pluginsField.setAccessible(true); plugins = (List) pluginsField.get(pluginManager); - Field lookupNamesField = Bukkit.getPluginManager().getClass() - .getDeclaredField("lookupNames"); + Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames"); lookupNamesField.setAccessible(true); - lookupNames = (Map) lookupNamesField - .get(pluginManager); + lookupNames = (Map) lookupNamesField.get(pluginManager); try { - Field listenersField = Bukkit.getPluginManager().getClass() - .getDeclaredField("listeners"); + Field listenersField = Bukkit.getPluginManager().getClass().getDeclaredField("listeners"); listenersField.setAccessible(true); - listeners = (Map>) listenersField - .get(pluginManager); + listeners = (Map>) listenersField.get(pluginManager); } catch (Exception e) { reloadlisteners = false; } - Field commandMapField = Bukkit.getPluginManager().getClass() - .getDeclaredField("commandMap"); + Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap"); commandMapField.setAccessible(true); - commandMap = (SimpleCommandMap) commandMapField - .get(pluginManager); + commandMap = (SimpleCommandMap) commandMapField.get(pluginManager); - Field knownCommandsField = SimpleCommandMap.class - .getDeclaredField("knownCommands"); + Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands"); knownCommandsField.setAccessible(true); - knownCommands = (Map) knownCommandsField - .get(commandMap); + knownCommands = (Map) knownCommandsField.get(commandMap); } catch (Exception e) { - sender.sendMessage("§c异常: " + e.getMessage() + " 插件 " + name - + " 卸载失败!"); + sender.sendMessage("§c异常: " + e.getMessage() + " 插件 " + name + " 卸载失败!"); return false; } } @@ -343,21 +324,19 @@ public class PluginsManager { lookupNames.remove(name); } - if (commandMap != null) - for (Iterator> it = knownCommands - .entrySet().iterator(); it.hasNext();) { + if (commandMap != null) { + for (Iterator> it = knownCommands.entrySet().iterator(); it.hasNext();) { Map.Entry entry = it.next(); if ((entry.getValue() instanceof PluginCommand)) { - PluginCommand command = (PluginCommand) entry - .getValue(); - + PluginCommand command = (PluginCommand) entry.getValue(); if (command.getPlugin() == next) { command.unregister(commandMap); it.remove(); } } } + } } } if (listeners != null && reloadlisteners) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ad9b2ec..0a48765 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,9 @@ -name: ${project.artifactId} -main: ${project.groupId}.${project.artifactId}.${project.artifactId} -version: ${project.version} -auther: 喵♂呜 -website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/ -commands: - yum: - description: MC插件仓库 +name: ${project.artifactId} +main: ${project.groupId}.${project.artifactId}.${project.artifactId} +version: ${project.version} +auther: 喵♂呜 +website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/ +commands: + yum: + description: MC插件仓库 usage: §6使用§a/yum help§6查看帮助! \ No newline at end of file