package com.btk5h.skriptmirror;

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;

import ch.njol.skript.Skript;

public class LibraryLoader {
  private static ClassLoader classLoader = LibraryLoader.class.getClassLoader();

  private static final PathMatcher MATCHER =
      FileSystems.getDefault().getPathMatcher("glob:**/*.jar");

  private static class LibraryVisitor extends SimpleFileVisitor<Path> {
    private List<URL> urls = new ArrayList<>();

    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
      if (MATCHER.matches(file)) {
        Skript.info("Loaded external library " + file.getFileName());
        urls.add(file.toUri().toURL());
      }
      return super.visitFile(file, attrs);
    }

    public URL[] getUrls() {
      return urls.toArray(new URL[urls.size()]);
    }
  }

  public static void loadLibraries() {
    Path dataFolder = SkriptMirror.getInstance().getDataFolder().toPath();
    if (Files.isDirectory(dataFolder)) {
      try {
        LibraryVisitor visitor = new LibraryVisitor();
        Files.walkFileTree(dataFolder, visitor);
        classLoader = new URLClassLoader(visitor.getUrls(), LibraryLoader.class.getClassLoader());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

  public static ClassLoader getClassLoader() {
    return classLoader;
  }
}

@@ -26,16 +26,47 @@
 irror;%0A%0A
+import ch.njol.skript.Skript;%0A%0A
 import j
@@ -85,16 +85,16 @@
 eption;%0A
-
 import j
@@ -163,186 +163,9 @@
 ile.
-FileSystems;%0Aimport java.nio.file.FileVisitResult;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.PathMatcher;%0Aimport java.nio.file.SimpleFileVisitor
+*
 ;%0Aim
@@ -270,39 +270,8 @@
 t;%0A%0A
-import ch.njol.skript.Skript;%0A%0A
 publ
@@ -1046,16 +1046,35 @@
 raries()
+ throws IOException
  %7B%0A    P
@@ -1188,22 +1188,8 @@
 ) %7B%0A
-      try %7B%0A  
     
@@ -1239,26 +1239,24 @@
 or();%0A      
-  
 Files.walkFi
@@ -1290,18 +1290,16 @@
 ;%0A      
- 
- 
 classLoa
@@ -1385,77 +1385,8 @@
 ));%0A
-      %7D catch (IOException e) %7B%0A        e.printStackTrace();%0A      %7D%0A
     

Make loadLibraries throw an exception instead of handling it