Update: The following advice no longer applies starting Minecraft 1.16, because developers can now use the “libraries” feature of their plugin.yml to include Nashorn library automatically. If you use our plugins such as ChatControl, Boss, CoreArena, Confiscate and Winter, this is done for you automatically. The advice below however, still applies if you decide to run Java 15+ on Minecraft 1.15 or older.

Minecraft is written in Java. However, it’s completely capable of running JavaScript code in real-time. We just need to give a little bit of help to get it working.

 

How to run JavaScript code using Java 8:

Java 8 introduced a library called Nashorn that was bundled within each installation. If you’re running Java 8, you can skip to using Nashorn and building Minecraft plugins that run JavaScript code. Here is a great tutorial on running JavaScript in Java, it’s a little old but nothing significant has changed since. It will work just fine today and for your Minecraft plugins.

However, in Java 15, the Nashorn library was removed. Developers that rely on JavaScript in their plugins have to reach for an alternative. We use JavaScript in almost all of our plugins, such as for different chat placeholders or custom scripts that users can create.

 

How to run JavaScript code using Java 15 and greater:

We’ve created a supplemental library called NashornPlus that enables you to keep using JavaScript code on Java 15 and higher. It uses an open source standalone Nashorn library (see below) and it makes your code compatible with Java 8 through the latest one without you needing to change anything!

 

How to use NashornPlus:

A) If you’re using one of our plugins like ChatControl Red, Boss, CoreArena or others, all you need to do is install NashornPlus as a plugin and that’s it.

B) If you’re developing your plugin using the Foundation library, all you need to do is install NashornPlus as a plugin and that’s it. Foundation automatically registers the library and you can run JavaScript code using the “JavaScriptExecutor” class in Foundation. Optionally, put “NashornPlus” into your soft-depend key in your plugin.yml.

C) If you’re developing your plugin without Foundation, install NashornPlus as a separate plugin, then import Nashorn as a Maven or Gradle dependency (do not include it in the final jar). You can use this code snippet as an example of importing and using it.

 

Download NashornPlus from here:

https://bitbucket.org/kangarko/nashornplus/downloads