package mods.quiddity.redux.JavaScript;

import jdk.nashorn.api.scripting.ClassFilter;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

import javax.script.ScriptException;

public class NashornEngine implements JavascriptEngine {
    private NashornScriptEngine nashornScriptEngine;

    @Override
    public void init() {
        if (nashornScriptEngine != null)
            killEngine();
        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        ccl = (ccl == null ? NashornScriptEngineFactory.class.getClassLoader() : ccl);
        nashornScriptEngine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine(new String[]{"--no-java"}, ccl, new ReduxClassFilter());
    }

    @Override
    public void loadScript(String script) throws ScriptException {
        nashornScriptEngine.eval(script);
    }

    @Override
    public void killEngine() {
        nashornScriptEngine = null;
    }

    @Override
    public void restartEngine() {
        init();
    }

    @Override
    public void addJavaObject(String name, Object object) {
        nashornScriptEngine.put(name, object);
    }

    @Override
    public boolean hasMethod(String name) {
        return nashornScriptEngine.get(name) != null;
    }

    @Override
    public void callMethod(String name, Object... args) throws ScriptException, NoSuchMethodException {
        nashornScriptEngine.invokeFunction(name, args);
    }

    class ReduxClassFilter implements ClassFilter {
        @Override
        public boolean exposeToScripts(String s) {
            return s.contentEquals("mods.quiddity.redux.Javascript.ReduxJavascriptEngine.ReduxAPI");
        }
    }
}

@@ -624,157 +624,720 @@
     
-nashornScriptEngine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine(new String%5B%5D%7B%22--no-java%22%7D, ccl, new ReduxClassFilter());
+try %7B%0A            /**%0A             * This was implemented somewhere between Java 1.8.0_31 and 1.8.0_40%0A             * For now make it optional, the --no-java argument should do most of the sandboxing anyways.%0A             */%0A            if (Class.forName(%22jdk.nashorn.api.scripting.ClassFilter%22) != null) %7B%0A                nashornScriptEngine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine(new String%5B%5D%7B%22--no-java%22%7D, ccl, new ReduxClassFilter());%0A            %7D%0A        %7D catch (ClassNotFoundException ignored) %7B %7D%0A%0A        if (nashornScriptEngine == null) %7B%0A            nashornScriptEngine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine(%22--no-java%22);%0A        %7D
 %0A   

Check for the existance of ClassFilter. This was implemented somewhere between Java 1.8.0_31 and 1.8.0_40. For now make it optional, the --no-java argument should do most of the sandboxing anyways