If you use Java 15 or above, you might need this plugin.
If you use Java 11 or below, you won't need this plugin.
Oracle is going to drop JavaScript engine from java distribution (deprecated in Java11 and dropped since Java15).
However, some plugins do use JavaScript engine to process various JavaScript code.
This plugin simply wraps openjdk's nashorn JavaScript engine and makes it available to other plugins.
The Nashorn version included in this distribution is : 15.4
To use JavaScript engine, you could do something like:
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 = getServer().getServicesManager();
if (!servicesManager.isProvidedFor(ScriptEngineManager.class)) {
ScriptEngineManager manager = new ScriptEngineManager();
servicesManager.register(ScriptEngineManager.class, manager, this, ServicePriority.Highest);
}
RegisteredServiceProvider<ScriptEngineManager> 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();
}