1414import java .io .FileInputStream ;
1515import java .io .IOException ;
1616import java .io .InputStream ;
17- import java .lang .reflect .InvocationTargetException ;
1817import java .net .URISyntaxException ;
1918import java .nio .file .DirectoryStream ;
2019import java .nio .file .Files ;
@@ -52,20 +51,19 @@ protected static void registerLibraries(final Skript skript) {
5251 final List <File > files = getFiles (new ArrayList <>(), LIBRARIES .toPath ());
5352 for (final File file : files ) {
5453 if (file .getName ().endsWith (".jar" )) {
55- try {
56- final JarFile jar = new JarFile (file );
54+ try (final JarFile jar = new JarFile (file )) {
5755 final String main = jar .getManifest ().getMainAttributes ().getValue ("Main-Class" );
5856 if (main == null )
59- throw new ScriptLibraryError ("Library '" + file .getName () + "' is missing main class in manifest." );
57+ throw new ScriptLibraryError ("Library '" + file .getName () + "' is missing a main class in its Jar manifest." );
6058 callLibrary (file , main , skript );
6159 } catch (Throwable ex ) {
6260 ex .printStackTrace ();
6361 }
6462 } else if (file .getName ().endsWith (".class" )) {
6563 try (final InputStream stream = new FileInputStream (file )) {
6664 skript .registerLibraryClass (stream .readAllBytes ());
67- } catch (IOException exception ) {
68- throw new ScriptLibraryError ("Error while loading library '" + file .getName () + "'" , exception );
65+ } catch (Throwable exception ) {
66+ throw new ScriptLibraryError ("Error while loading class library '" + file .getName () + "'" , exception );
6967 }
7068 }
7169 }
@@ -76,9 +74,14 @@ protected static void callLibrary(final File file, final String main, final Skri
7674 final Class <?> target = Class .forName (main , true , child );
7775 try {
7876 target .getMethod ("load" , Skript .class ).invoke (null , skript );
79- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex ) {
80- throw new ScriptLibraryError ("Library '" + file .getName () + "' main class is missing load method:\n " +
77+ } catch (NoSuchMethodException ex ) {
78+ throw new ScriptLibraryError ("Library '" + file .getName () + "' main class is missing a load method:\n " +
8179 "public static void load(Skript skript)\n " );
80+ } catch (IllegalAccessException ex ) {
81+ throw new ScriptLibraryError ("Library '" + file .getName () + "' main class has no public load method:\n " +
82+ "public static void load(Skript skript)\n " );
83+ } catch (Throwable ex ) {
84+ throw new ScriptLibraryError ("Error encountered while loading '" + file .getName () + "':" , ex );
8285 }
8386 }
8487
0 commit comments