Creating a module
Modules add features to Plex without changing the core plugin. This guide shows you how to build one. You should know Java, Git, and the Gradle build system before you start.
A module is a normal Paper plugin JAR with one difference. It carries a module.yml file instead of a plugin.yml file,
and it extends the Plex module API instead of the Bukkit JavaPlugin class. Plex loads the JAR, reads its metadata, and
calls the module through a small, stable API.
You do not talk to Plex internals. You talk to the dev.plex:api artifact only. This keeps modules working across Plex
updates, as long as the API compatibility number stays the same.
How a module works
Section titled “How a module works”Plex loads every JAR in plugins/Plex/modules/ at startup. For each module, Plex reads module.yml, creates an instance
of your main class, and gives it a data folder, a logger, and the Plex API. Plex then drives the module through three
lifecycle methods.
load()runs first, for every module, before any module is enabled. Most modules do not need it.enable()runs next, for every module. Register your commands and listeners and read your configuration here.disable()runs at shutdown or reload. Plex unregisters your commands and listeners for you. Release any other resources here.
You reach every supported feature through one method, api(). It returns the Plex API facade. From there you call
api().players(), api().messages(), api().punishments(), and the other services. The
Plex API reference page lists them all.
Updates
Section titled “Updates”Plex can update installed modules with /plex modules update. This command uses Plex’s first-party updater, which serves
the official modules only. If you publish a third-party module, tell Plex where to find your updates, or turn updates off.
- Set
updater.urlinmodule.ymlto serve updates from your own location. - Set
updater.enabled: falseto keep your module out of/plex modules update.
The ExampleModule template turns updates off. See Build and install for the full updater block.
The rest of this guide
Section titled “The rest of this guide”Read the pages in order to build a module from start to finish.
- Project setup starts from the ExampleModule template and sets up the Gradle files, the module descriptor, and the main class.
- Commands adds a command.
- Listeners adds a listener.
- Configuration and messages adds a config file and a message file.
- Libraries and storage adds runtime libraries, database storage, and scheduled tasks.
- The Plex API lists every service that a module can use.
- Build and install builds the module and installs it on a server.
