JSEngine 3.0.4

Wrapper for Nashorn JavaScript engine

  1. vk2gpz
    Native Minecraft Version:
    1.13
    Tested Minecraft Versions:
    • 1.7
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    • 1.13
    • 1.14
    • 1.15
    • 1.16
    • 1.17
    Source Code:
    https://github.com/TeamVK/JSEngine
    Contributors:
    vk2gpz
    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.2

    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();
    }
     

Recent Reviews

  1. Happiys
    Happiys
    5/5,
    Version: 3.0.3
    The perfect plugin to add back what java 15 removed. Also fixed some plugins that used Java 11 coding and haven't updated for my server. Good Work!