Advertisement
Guest User

Untitled

a guest
Sep 17th, 2020
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1.     public void LoadScripts() {
  2.         scripts.clear();
  3.         File f = new File(System.getProperty("user.dir") + "/Scripts");
  4.         String[] files = f.list();
  5.         System.out.println("Loading scripts..");
  6.         ArrayList<URL> urlList = new ArrayList<URL>();
  7.  
  8.         for (int i = 0; i < files.length; ++i) {
  9.             try {
  10.                 urlList.add(new File(files[i]).toURI().toURL());
  11.             } catch (MalformedURLException e) { System.out.println("Could not turn '" + files[i] + "into a url!"); }
  12.         }
  13.         URL[] urls = new URL[urlList.size()];
  14.         urls = urlList.toArray(urls);
  15.  
  16.         int counter = 0;
  17.         long timer = System.currentTimeMillis();
  18.         try {
  19.             URLClassLoader cl = new URLClassLoader(urls);
  20.            
  21.             for (int i = 0; i < files.length; i++) {
  22.                 if (files[i].endsWith(".class") && files[i].indexOf("$") == -1) {
  23.                     try {
  24.                         String fileName = files[i].substring(0, files[i].length() - ".class".length());
  25.  
  26.                         Class clazz = cl.loadClass(fileName);
  27.  
  28.                         IScript macro = (IScript)clazz.getConstructor(IScriptMethods.class, String.class).newInstance(this, fileName);
  29.                         //fileName = fileName.toLowerCase();
  30.                         scripts.put(fileName, macro);
  31.                         counter++;
  32.                         System.out.println("Found script: " + fileName);
  33.                     } catch (Exception e_) {
  34.                         System.out.println("Errorneous script: " + files[i] + " - " + e_.toString());
  35.                         e_.printStackTrace();
  36.                     }
  37.                 }
  38.             }
  39.         } catch (Exception e) {
  40.             e.printStackTrace();
  41.         }
  42.         long time = System.currentTimeMillis() - timer;
  43.         System.out.println("Done loading: " + counter + " scripts in: " + time + "ms");
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement