thrownew IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", className, className), ex); } catch (Exception ex) { thrownew IllegalArgumentException(String.format("Unexpected exception %s while attempting to construct a new instance of %s", ex.getClass().getName(), loader.getName()), ex); } } else { thrownew IllegalArgumentException(String.format("Class %s does not implement interface PluginLoader", loader.getName())); }
public Plugin[] loadPlugins(File directory) { Validate.notNull(directory, "Directory cannot be null"); Validate.isTrue(directory.isDirectory(), "Directory must be a directory");
List<Plugin> result = new ArrayList<Plugin>(); Set<Pattern> filters = fileAssociations.keySet();
if (!(server.getUpdateFolder().equals(""))) { updateDirectory = new File(directory, server.getUpdateFolder()); }
Map<String, File> plugins = new HashMap<String, File>(); Set<String> loadedPlugins = new HashSet<String>(); Map<String, Collection<String>> dependencies = new HashMap<String, Collection<String>>(); Map<String, Collection<String>> softDependencies = new HashMap<String, Collection<String>>();
// This is where it figures out all possible plugins for (File file : directory.listFiles()) { PluginLoader loader = null; for (Pattern filter : filters) { Matcher match = filter.matcher(file.getName()); if (match.find()) { loader = fileAssociations.get(filter); } }
if (loader == null) continue;
PluginDescriptionFile description = null; try { description = loader.getPluginDescription(file); String name = description.getName(); if (name.equalsIgnoreCase("bukkit") || name.equalsIgnoreCase("minecraft") || name.equalsIgnoreCase("mojang")) { server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': Restricted Name"); continue; } elseif (description.rawName.indexOf(' ') != -1) { server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': uses the space-character (0x20) in its name"); continue; } } catch (InvalidDescriptionException ex) { server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex); continue; }
File replacedFile = plugins.put(description.getName(), file); if (replacedFile != null) { server.getLogger().severe(String.format( "Ambiguous plugin name `%s' for files `%s' and `%s' in `%s'", description.getName(), file.getPath(), replacedFile.getPath(), directory.getPath() )); } //省去通过依赖分析来决定加载顺序。 return result.toArray(new Plugin[result.size()]); }
final File parentFile = file.getParentFile(); final File dataFolder = new File(parentFile, description.getName()); @SuppressWarnings("deprecation") final File oldDataFolder = new File(parentFile, description.getRawName());
// Found old data folder if (dataFolder.equals(oldDataFolder)) { // They are equal -- nothing needs to be done! } elseif (dataFolder.isDirectory() && oldDataFolder.isDirectory()) { server.getLogger().warning(String.format( "While loading %s (%s) found old-data folder: `%s' next to the new one `%s'", description.getFullName(), file, oldDataFolder, dataFolder )); } elseif (oldDataFolder.isDirectory() && !dataFolder.exists()) { if (!oldDataFolder.renameTo(dataFolder)) { thrownew InvalidPluginException("Unable to rename old data folder: `" + oldDataFolder + "' to: `" + dataFolder + "'"); } server.getLogger().log(Level.INFO, String.format( "While loading %s (%s) renamed data folder: `%s' to `%s'", description.getFullName(), file, oldDataFolder, dataFolder )); }
if (dataFolder.exists() && !dataFolder.isDirectory()) { thrownew InvalidPluginException(String.format( "Projected datafolder: `%s' for %s (%s) exists and is not a directory", dataFolder, description.getFullName(), file )); }
for (final String pluginName : description.getDepend()) { Plugin current = server.getPluginManager().getPlugin(pluginName);
if (current == null) { thrownew UnknownDependencyException(pluginName); } }