JSEngine icon

JSEngine -----

Wrapper for Nashorn JavaScript engine



supports different ways to access the engine.
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();
}
 
----------, May 27, 2021
Resource Information
Author:
----------
Total Downloads: 5,779
First Release: May 26, 2021
Last Update: Oct 4, 2024
Category: ---------------
All-Time Rating:
7 ratings
Find more info at discord.gg...
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings