PluginDataFile data = null;
if (file.getName().endsWith(".py")) {
if (file.isDirectory())
//cause we can't throw InvalidPluginExceptions from here we throw an InvalidDescriptionExecption with the InvalidPlugin as cause
throw new InvalidDescriptionException(new InvalidPluginException(new Exception("python files cannot be directories! try .py.dir instead.")));
data = new PluginPythonFile(file);
} else if (file.getName().endsWith("dir")) {
if (!file.isDirectory())
throw new InvalidDescriptionException(new InvalidPluginException(new Exception("python directories cannot be normal files! try .py or .py.zip instead.")));
data = new PluginPythonDirectory(file);
} else if (file.getName().endsWith("zip") || file.getName().endsWith("pyp")) {
if (file.isDirectory())
throw new InvalidDescriptionException(new InvalidPluginException(new Exception("python zips cannot be directories! try .py.dir instead.")));
try {
data = new PluginPythonZip(file);
} catch (InvalidPluginException ex) {
throw new InvalidDescriptionException(ex);
}
} else {
throw new InvalidDescriptionException(new InvalidPluginException(new Exception("filename '"+file.getName()+"' does not end in py, dir, zip, or pyp! did you add a regex without altering loadPlugin()?")));
}
try {
stream = data.getStream("plugin.yml");
if(stream == null) {
//TODO Does this cause serious problems with plugins which have no plugin.yml file?
throw new InvalidDescriptionException(new InvalidPluginException(new FileNotFoundException("Jar does not contain plugin.yml")));
}
return new PluginDescriptionFile(stream);
} catch (IOException e) {
e.printStackTrace();