Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void LoadScripts() {
- scripts.clear();
- File f = new File(System.getProperty("user.dir") + "/Scripts");
- String[] files = f.list();
- System.out.println("Loading scripts..");
- ArrayList<URL> urlList = new ArrayList<URL>();
- for (int i = 0; i < files.length; ++i) {
- try {
- urlList.add(new File(files[i]).toURI().toURL());
- } catch (MalformedURLException e) { System.out.println("Could not turn '" + files[i] + "into a url!"); }
- }
- URL[] urls = new URL[urlList.size()];
- urls = urlList.toArray(urls);
- int counter = 0;
- long timer = System.currentTimeMillis();
- try {
- URLClassLoader cl = new URLClassLoader(urls);
- for (int i = 0; i < files.length; i++) {
- if (files[i].endsWith(".class") && files[i].indexOf("$") == -1) {
- try {
- String fileName = files[i].substring(0, files[i].length() - ".class".length());
- Class clazz = cl.loadClass(fileName);
- IScript macro = (IScript)clazz.getConstructor(IScriptMethods.class, String.class).newInstance(this, fileName);
- //fileName = fileName.toLowerCase();
- scripts.put(fileName, macro);
- counter++;
- System.out.println("Found script: " + fileName);
- } catch (Exception e_) {
- System.out.println("Errorneous script: " + files[i] + " - " + e_.toString());
- e_.printStackTrace();
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- long time = System.currentTimeMillis() - timer;
- System.out.println("Done loading: " + counter + " scripts in: " + time + "ms");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement