Your First Plugin
This page walks through converting the example package into your own plugin from scratch.
1. Rename the package
Section titled β1. Rename the packageβRename me.dzusill.core.example to your package (e.g. me.yourname.myplugin). In IntelliJ IDEA: right-click the package β Refactor β Rename.
2. Create your main class
Section titled β2. Create your main classβExtend CorePlugin and implement modules():
public class MyPlugin extends CorePlugin {
@Override protected CoreModule[] modules() { return new CoreModule[]{ new FoundationModule(this), // config + messages + scheduler + listeners new CommandModule(this) // your commands }; }
@Override protected String[] banner() { return new String[]{ "", " MyPlugin v" + getPluginMeta().getVersion(), "" }; }}Do not override
onEnable()oronDisable(). These are declaredfinalinCorePluginand managed byModuleManager. Use theonPreEnable(),onPostEnable(), andonPreDisable()hooks instead, or put startup logic in a module.
3. Update plugin.yml
Section titled β3. Update plugin.ymlβname: MyPluginversion: '1.0.0'main: me.yourname.myplugin.MyPluginapi-version: '1.21'description: My awesome pluginauthors: [yourname]softdepend: [Vault, PlaceholderAPI, Essentials] # remove any you don't need4. Create your first module
Section titled β4. Create your first moduleβA module groups a logical subsystem (commands, menus, a data serviceβ¦). The minimum:
public final class CommandModule extends AbstractModule {
public CommandModule(CorePlugin plugin) { super(plugin); }
@Override public String name() { return "Commands"; }
@Override public void onEnable() { CommandRegistry commands = service(CommandRegistry.class); commands.register(new MyCommand()); }}5. Build and run
Section titled β5. Build and runβmvn packagecp target/MyPlugin-1.0.0.jar /path/to/server/plugins/Start the server. The banner you defined in banner() will appear in the console on startup.
Module order matters
Section titled βModule order mattersβModules are enabled in the order you declare them in modules() and disabled in reverse order. Always declare foundation modules (config, messages, scheduler) before the modules that depend on them.
return new CoreModule[]{ new FoundationModule(this), // provides ConfigManager, MessageService, SchedulerService new DatabaseModule(this), // requires SchedulerService β must come after Foundation new MenuModule(this), // requires MenuManager new CommandModule(this) // requires everything above};