Skip to content

Implementation Docs

Jonathan Crowder (Jon) edited this page Apr 21, 2020 · 4 revisions

RepCraft class

RepCraft is implemented as a spigot api JavaPlugin

Graalvm usage

Graalvm is a platform where many languages (polyglot) can run in the same environment.
RepCraft uses this to have JavaScript interop with Java

Graalvm runs a JVM (Java Virtual Machine) that takes place of Oracle's
Which the minecraft spigot server needs to launch inside of
This allows RepCraft to access the polyglot api and run JavaScript

JavaScript plugin loading

Under the hood, RepCraft simply looks in <spigot>/repcraft/js-plugins
for sub-directories that have a package.json file in them.

RepCraft uses Gson for parsing JSON,
this was chosen because spigot loads gson already.

When it finds package.json it attempts to read main property
which it tries to treat as a JavaScript file path run in graalvm. As per graalvm docs, sources that end in .mjs are treated as ES Modules.

A more advanced implementation of spigot Listener class.
It registers itself as a handler of every event type,
and provides a JavaScript exposed API for listening in JS.

JS Command

This one is pretty simple
it is a regular minecraft command processor that
joins the command text into a single string
and feeds it into graalvm for evaluation

Permissions are not yet implemented.

Clone this wiki locally