You can access JS engine in three different ways;
1) use JSEngine.jar as a library
Code (Text):
import com.vk2gpz.jsengine.JSEngine;
...
public class Foo {
void bar() {
ScriptEngine engine = JSEngine.getNewEngine();
try {
engine.eval("your script");
} catch (javax.script.ScriptException ex) {
ex.printStackTrace();
}
...
}
2) use JSEngine as a plugin
Code (Text):
Plugin plugin = Bukkit.getPluginManager().getPlugin("JSEngine");
if (plugin != null) {
engine = (ScriptEngine) ((JSEngine) plugin).getSharedEngine();
//engine = (ScriptEngine) ((JSEngine) plugin).getNewEngine();
}
...
if (engine != null) {
try {
engine.eval("...you script");
} catch (javax.script.ScriptException ex) {
ex.printStackTrace();
}
}
3) use JSEngine through Bukkit's ServicesManager
Code (Text):
ServicesManager servicesManager = Bukkit.getServer().getServicesManager().getRegistration(ScriptEngineManager.class);
ScriptEngineManager scriptEngineManager = servicesManager.getProvider();
ScriptEngine engine = scriptEngineManager.getEngineByName("js");
try {
engine.eval("your script");
} catch (javax.script.ScriptException ex) {
ex.printStackTrace();
}