版本更新至:3.76

调整:开发框架改为 Gradle
新增:Language2 工具新增 [book] 类型
This commit is contained in:
坏黑
2018-03-10 21:13:05 +08:00
parent 6439e4b780
commit ad1a21196f
238 changed files with 1686 additions and 1132 deletions

View File

@@ -0,0 +1,90 @@
package me.skymc.taboolib.javascript;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import me.skymc.taboolib.Main;
public class JavaScriptUtils {
private static ScriptEngineManager manager = new ScriptEngineManager();
public static ScriptEngineManager getScriptManager() {
return manager;
}
public static void invokeJavaScript(File jsFile, String method, Object... o) {
ScriptEngine engine = manager.getEngineByName("javascript");
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(Main.class.getClassLoader());
FileReader reader = new FileReader(jsFile);
engine.eval(reader);
// TODO run
Thread.currentThread().setContextClassLoader(classLoader);
}
catch (Exception e) {
// TODO: handle exception
}
}
@Deprecated
public static Object JavaScriptInterface(String jsFile, Object... o) {
ScriptEngine engine = manager.getEngineByName("javascript");
try {
FileReader reader = new FileReader(jsFile);
engine.eval(reader);
if (engine instanceof Invocable) {
return ((Invocable) engine).invokeFunction("main", o);
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ScriptException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
@Deprecated
public static void JavaScriptExecute(String jsFile, Object... o) {
ScriptEngine engine = manager.getEngineByName("javascript");
try {
FileReader reader = new FileReader(jsFile);
engine.eval(reader);
if (engine instanceof Invocable) {
((Invocable) engine).invokeFunction("main", o);
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ScriptException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}