mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-24 09:02:00 +01:00
Added comments for clarity.
This commit is contained in:
parent
037bf04836
commit
32794a5d3f
@ -100,34 +100,48 @@ public final class AddonsManager {
|
|||||||
private void loadAddon(File f) throws InvalidAddonFormatException, InvalidAddonInheritException, InvalidDescriptionException {
|
private void loadAddon(File f) throws InvalidAddonFormatException, InvalidAddonInheritException, InvalidDescriptionException {
|
||||||
try {
|
try {
|
||||||
Addon addon = null;
|
Addon addon = null;
|
||||||
|
// Check that this is a jar
|
||||||
if (!f.getName().contains(".jar")) {
|
if (!f.getName().endsWith(".jar")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JarFile jar = new JarFile(f);
|
JarFile jar = new JarFile(f);
|
||||||
JarEntry entry = jar.getJarEntry("addon.yml");
|
|
||||||
|
|
||||||
|
// Obtain the addon.yml file
|
||||||
|
JarEntry entry = jar.getJarEntry("addon.yml");
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
jar.close();
|
jar.close();
|
||||||
throw new InvalidAddonFormatException("Addon doesn't contains description file");
|
throw new InvalidAddonFormatException("Addon doesn't contains description file");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Open a reader to the jar
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
|
||||||
|
// Grab the description in the addon.yml file
|
||||||
Map<String, String> data = this.data(reader);
|
Map<String, String> data = this.data(reader);
|
||||||
|
|
||||||
AddonClassLoader loader = null;
|
// Load the addon
|
||||||
|
AddonClassLoader loader = new AddonClassLoader(this, data, f, reader, this.getClass().getClassLoader());
|
||||||
loader = new AddonClassLoader(this, data, f, reader, this.getClass().getClassLoader());
|
// Add to the list of loaders
|
||||||
this.loader.add(loader);
|
this.loader.add(loader);
|
||||||
|
|
||||||
|
// Get the addon itseld
|
||||||
addon = loader.addon;
|
addon = loader.addon;
|
||||||
|
// Initialize some settings
|
||||||
addon.setDataFolder(new File(f.getParent(), addon.getDescription().getName()));
|
addon.setDataFolder(new File(f.getParent(), addon.getDescription().getName()));
|
||||||
addon.setAddonFile(f);
|
addon.setAddonFile(f);
|
||||||
|
|
||||||
|
// Fire the load event
|
||||||
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
||||||
|
|
||||||
|
// Add it to the list of addons
|
||||||
this.addons.add(addon);
|
this.addons.add(addon);
|
||||||
|
|
||||||
|
// Run the onLoad() method
|
||||||
addon.onLoad();
|
addon.onLoad();
|
||||||
|
|
||||||
|
// Inform the console
|
||||||
BSkyBlock.getInstance().getLogger().info("Loading BSkyBlock addon " + addon.getDescription().getName() + "...");
|
BSkyBlock.getInstance().getLogger().info("Loading BSkyBlock addon " + addon.getDescription().getName() + "...");
|
||||||
|
|
||||||
|
// Close the jar
|
||||||
jar.close();
|
jar.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
Loading…
Reference in New Issue
Block a user