Skip to content

Developer Modules

BananaPuncher714 edited this page Jul 15, 2020 · 5 revisions

pig

Modules are addons that provide functionality directly though Cartographer, rather than registering itself as a separate plugin. For more information on how to install them, visit here.

Dependencies

If your module depends on other plugins, such as factions, or placeholders, you can specify it as a dependency in the module.json and it will get loaded after the dependency, or warn the console of the missing dependencies.

Basic structure

Like a regular plugin, a module requires a file describing its properties and entry point. The file must be named module.json and have these properties:

Name Value Required
name The name of the module. Can only contain the following characters: A-Za-z0-9_.- true
main The path to the class of the module. true
description The description of the module. true
version The version of the module. true
author The author of the module. true
website The website of the author. false
depend Any dependencies. May be a string or a string list. false
dependencies Same as depend, only one is used. false

Here is an example.

Module class

The main class must extend Module. Like a plugin, you will want to override onEnable and onDisable for module enable and disable. Unlike a plugin, it is highly recommended to properly disable your plugin in the onDisable method, since your module may cause issues if you do not clean up when it is disabled or unloaded.

public class ExampleModule extends Module {
  @Override
  public void onEnable() {
    // Do your stuff here, like registering listeners, running tasks, saving files, loading configs and locales.
  }

  @Override
  public void onDisable() {
    // Clean up your plugin here.
    // You don't have to unregister listeners or stop tasks that you started with Module#registerListener() or Module#runTaskTimer().
  }

  @Override
  public Collection< Locale > getLocales() {
    // Optional locale system
    return new ArrayList< Locale >();
  }

  @Override
  public SettingState< ? >[] getSettingStates() {
    // Optional settings to attach to players that persist over server restarts
    return new SettingState< ? >[ 0 ];
  }
}

It contains these methods. To access the Cartographer instance, use Module#getCartographer(). If the javadocs don't update, view the source here.