mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 18:55:17 +01:00
Used try-with-resources to ensure jar is closed.
This commit is contained in:
parent
28b88763e6
commit
56ff9f62e4
@ -101,53 +101,52 @@ public final class AddonsManager {
|
|||||||
if (!f.getName().endsWith(".jar")) {
|
if (!f.getName().endsWith(".jar")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JarFile jar = new JarFile(f);
|
try (JarFile jar = new JarFile(f)) {
|
||||||
|
|
||||||
// Obtain the addon.yml file
|
|
||||||
JarEntry entry = jar.getJarEntry("addon.yml");
|
|
||||||
if (entry == null) {
|
|
||||||
jar.close();
|
|
||||||
throw new InvalidAddonFormatException("Addon doesn't contains description file");
|
|
||||||
|
|
||||||
}
|
// Obtain the addon.yml file
|
||||||
// Open a reader to the jar
|
JarEntry entry = jar.getJarEntry("addon.yml");
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
|
if (entry == null) {
|
||||||
// Grab the description in the addon.yml file
|
jar.close();
|
||||||
Map<String, String> data = this.data(reader);
|
throw new InvalidAddonFormatException("Addon doesn't contains description file");
|
||||||
|
|
||||||
// Load the addon
|
}
|
||||||
AddonClassLoader loader = new AddonClassLoader(this, data, f, reader, this.getClass().getClassLoader());
|
// Open a reader to the jar
|
||||||
// Add to the list of loaders
|
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));
|
||||||
this.loader.add(loader);
|
// Grab the description in the addon.yml file
|
||||||
|
Map<String, String> data = this.data(reader);
|
||||||
// Get the addon itself
|
|
||||||
addon = loader.addon;
|
// Load the addon
|
||||||
// Initialize some settings
|
AddonClassLoader loader = new AddonClassLoader(this, data, f, reader, this.getClass().getClassLoader());
|
||||||
addon.setDataFolder(new File(f.getParent(), addon.getDescription().getName()));
|
// Add to the list of loaders
|
||||||
addon.setAddonFile(f);
|
this.loader.add(loader);
|
||||||
|
|
||||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + addon.getDescription().getName());
|
// Get the addon itself
|
||||||
// Obtain any locale files and save them
|
addon = loader.addon;
|
||||||
for (String localeFile : listJarYamlFiles(jar, "locales")) {
|
// Initialize some settings
|
||||||
//plugin.getLogger().info("DEBUG: saving " + localeFile + " from jar");
|
addon.setDataFolder(new File(f.getParent(), addon.getDescription().getName()));
|
||||||
addon.saveResource(localeFile, localeDir, false, true);
|
addon.setAddonFile(f);
|
||||||
|
|
||||||
|
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + addon.getDescription().getName());
|
||||||
|
// Obtain any locale files and save them
|
||||||
|
for (String localeFile : listJarYamlFiles(jar, "locales")) {
|
||||||
|
//plugin.getLogger().info("DEBUG: saving " + localeFile + " from jar");
|
||||||
|
addon.saveResource(localeFile, localeDir, false, true);
|
||||||
|
}
|
||||||
|
plugin.getLocalesManager().loadLocales(addon.getDescription().getName());
|
||||||
|
|
||||||
|
// Fire the load event
|
||||||
|
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
||||||
|
|
||||||
|
// Add it to the list of addons
|
||||||
|
this.addons.add(addon);
|
||||||
|
|
||||||
|
// Run the onLoad() method
|
||||||
|
addon.onLoad();
|
||||||
|
|
||||||
|
// Inform the console
|
||||||
|
plugin.getLogger().info("Loading BSkyBlock addon " + addon.getDescription().getName() + "...");
|
||||||
}
|
}
|
||||||
plugin.getLocalesManager().loadLocales(addon.getDescription().getName());
|
|
||||||
|
|
||||||
// Fire the load event
|
|
||||||
Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
|
||||||
|
|
||||||
// Add it to the list of addons
|
|
||||||
this.addons.add(addon);
|
|
||||||
|
|
||||||
// Run the onLoad() method
|
|
||||||
addon.onLoad();
|
|
||||||
|
|
||||||
// Inform the console
|
|
||||||
plugin.getLogger().info("Loading BSkyBlock addon " + addon.getDescription().getName() + "...");
|
|
||||||
|
|
||||||
// Close the jar
|
|
||||||
jar.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info(f.getName() + "is not a jarfile, ignoring...");
|
plugin.getLogger().info(f.getName() + "is not a jarfile, ignoring...");
|
||||||
@ -201,7 +200,7 @@ public final class AddonsManager {
|
|||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a class by name that has been loaded by this loader
|
* Finds a class by name that has been loaded by this loader
|
||||||
* Code copied from Bukkit JavaPluginLoader
|
* Code copied from Bukkit JavaPluginLoader
|
||||||
|
Loading…
Reference in New Issue
Block a user