MCPcopy Create free account
hub / github.com/Bukkit/Bukkit / JavaPluginLoader

Class JavaPluginLoader

src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java:38–997  ·  view source on GitHub ↗

Represents a Java plugin loader, allowing plugins in the form of .jar

Source from the content-addressed store, hash-verified

36 * Represents a Java plugin loader, allowing plugins in the form of .jar
37 */
38public class JavaPluginLoader implements PluginLoader {
39 private final Server server;
40 protected final Pattern[] fileFilters = new Pattern[] {
41 Pattern.compile("\\.jar$"),
42 };
43 protected final Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
44 protected final Map<String, PluginClassLoader> loaders = new HashMap<String, PluginClassLoader>();
45
46 public JavaPluginLoader(Server instance) {
47 server = instance;
48 }
49
50 public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
51 return loadPlugin(file, false);
52 }
53
54 public Plugin loadPlugin(File file, boolean ignoreSoftDependencies) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
55 JavaPlugin result = null;
56 PluginDescriptionFile description = null;
57
58 if (!file.exists()) {
59 throw new InvalidPluginException(new FileNotFoundException(String.format("%s does not exist", file.getPath())));
60 }
61 try {
62 JarFile jar = new JarFile(file);
63 JarEntry entry = jar.getJarEntry("plugin.yml");
64
65 if (entry == null) {
66 throw new InvalidPluginException(new FileNotFoundException("Jar does not contain plugin.yml"));
67 }
68
69 InputStream stream = jar.getInputStream(entry);
70
71 description = new PluginDescriptionFile(stream);
72
73 stream.close();
74 jar.close();
75 } catch (IOException ex) {
76 throw new InvalidPluginException(ex);
77 } catch (YAMLException ex) {
78 throw new InvalidPluginException(ex);
79 }
80
81 File dataFolder = new File(file.getParentFile(), description.getName());
82 File oldDataFolder = getDataFolder(file);
83
84 // Found old data folder
85 if (dataFolder.equals(oldDataFolder)) {
86 // They are equal -- nothing needs to be done!
87 } else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) {
88 server.getLogger().log(Level.INFO, String.format(
89 "While loading %s (%s) found old-data folder: %s next to the new one: %s",
90 description.getName(),
91 file,
92 oldDataFolder,
93 dataFolder
94 ));
95 } else if (oldDataFolder.isDirectory() && !dataFolder.exists()) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected