Creating Minecraft plugins using JavaScript

JavaScript and Java in Minecraft

Typically, Minecraft plugins are programmed in Java. This is the language Minecraft is made in. However, compared to JavaScript, Java can be quite a challenging language to learn. We can develop our own Minecraft Plugins using an existing plugin that allows us to run JavaScript code in Minecraft. ScriptCraft allows for JavaScript commands to be executed from within Minecraft. You can do basic mathematical operations or run complex scripts, and anything in between.

Getting Started

You will need to install a Spigot / Paper Spigot server. Head over to our How to create a Minecraft Server blog to see how to download and install a server. If you wish to install a Spigot server instead of Paper, follow the paper instructions but instead download a Spigot server.

Installing ScriptCraft

Head to https://github.com/walterhiggins/ScriptCraft/releases/tag/3.4.0 and download ScriptCraft.jar once downloaded, place the file inside your plugins folder. Once inside your plugins folder, run the server again. To confirm it is installed correctly type in the console: “js 2+2”. If this returns 4 then ScriptCraft is installed correctly.

Installing Notepad++

Navigate to https://notepad-plus-plus.org/downloads/ and download and install the latest version, this is what we will code our JavaScript in.

Useful Commands

You can use /js refresh() to check for any changes you have made to your plugins. This means that you will not need to keep restarting the server.

Your First Plugin

Open Notepad++ and type:

exports.greet = function( player ) {
    echo( player, 'Hi ' + player.name);
}

Save the file into Plugins/ScriptCraft/Plugins folder and name your script hi. Make sure to change the file type to All Files

Inside the Minecraft server type: /js hi(self)

jscommand.png

It will then display Hi {Your Player Name}.

serverreply.png

To further develop your plugin check out our JavaScript & Web Development course where you will learn how to program and develop your own website which you will then be able to transfer your skills gained into programming in JavaScript to create your own plugins. Once you are proficient in JavaScript you can move onto programming in Java to create even more plugins and begin creating Minecraft Mods