Skip to content

Structure of a plugin

Jonathan Crowder (Jon) edited this page Apr 22, 2020 · 3 revisions

For a functioning, more complex example see: https://github.com/RepComm/extrude-repcraft

JavaScript plugins at a minimum are made of up 3 things:

  1. It's folder/directory
  2. It's package.json definition
  3. A javascript file

All plugins reside in their own folders,
all of which reside in <spigot-home>/repcraft/js-plugins
NOTE: the js-plugins folder won't exist until you run spigot at least once with RepCraft installed.

Package.json

This is a basic json formatted file. It is mainly for RepCraft to discover your plugin with.

The only required member is main, which should point to your main javascript file.

{
  "main":"myPlugin.js"
}

Main JavaScript file

This is where your plugin code goes!
You may opt to use .js as the extension,
however, you may use ES Modules if you choose .mjs as the extension.
Logically your code doesn't have to be any different from .js
however, you gain a lot of abilities from modules.

There is no boiler-plate / starting code required for your plugin to load correctly. The simplest plugin code is something like:

console.log("Hello World! My js plugin has loaded!");
Clone this wiki locally