Public feed #722348

Someone

public java v1 · immutable
Raw Edit
·published 2007-10-01 22:54 UTC
rendered paste body
package pserver;import java.util.*;import java.io.*;import bsh.*;public class ScriptManager {    static ArrayList<Interpreter> scripts = new ArrayList<Interpreter>();    static File scriptRoot = new File("scripts/");    public static void loadScripts() {        callBack("unload");        scripts.clear();        try {            File[] files = scriptRoot.listFiles();            for (File f : files) {                Interpreter i = new Interpreter();                i.source(f.getAbsolutePath());                scripts.add(i);            }            System.out.println("[ScriptManager] Loaded " + scripts.size() + " scripts");            callBack("load");        } catch (Exception ex) {            ex.printStackTrace();        }    }    public static void callBack(String name, Object... args) {        try {            for (int i = 0; i < scripts.size(); i++) {                Interpreter script = scripts.get(i);                for (BshMethod method : script.getNameSpace().getMethods()) {                    if (method.getName().equals(name)) {                        method.invoke(args, script);                        break;                    }                }            }        } catch (Exception ex) {            ex.printStackTrace();        }    }}