Skip to content

Instantly share code, notes, and snippets.

@greatman
Created June 30, 2013 04:36
Show Gist options
  • Save greatman/5893870 to your computer and use it in GitHub Desktop.
Save greatman/5893870 to your computer and use it in GitHub Desktop.
JarFile jarFile = new JarFile(file);
//We load the basic game Plugin configuration
ZipEntry configFile = jarFile.getEntry("gameplugin.yml");
//Does the config file exists?
if (configFile != null) {
YamlConfiguration gamePlugin = YamlConfiguration.loadConfiguration(jarFile.getInputStream(configFile));
//Is the configuration a valid one?
if (!gamePlugin.contains("main-class") || !gamePlugin.contains("name")) {
ultimateGames.getMessageManager().log(Level.SEVERE, "Game " + file.getAbsolutePath() + " contains a invalid gameplugin.yml file!");
jarFile.close();
continue;
}
//We try to laod the main class..
pluginClassLoader.addUrl(file.toURI().toURL());
Class<?> clazz = pluginClassLoader.loadClass(gamePlugin.getString("main-class"));
//Is the class a valid game plugin?
if (GamePlugin.class.isAssignableFrom(clazz)) {
ultimateGames.getMessageManager().log(Level.INFO, "Loading " + gamePlugin.getString("name"));
GamePlugin plugin = (GamePlugin) clazz.newInstance();
} else {
ultimateGames.getMessageManager().log(Level.SEVERE, "Game " + gamePlugin.getString("name") + " got a invalid main class!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment