Plugins - Willsr71/Jarvis GitHub Wiki
Creating Plugins
You need a base class that extends Module.class and a plugin.json file
build.gradle
repositories {
maven { url "https://repo.noxal.net/artifactory/gradle-dev-local" }
}
dependencies {
compile "sr.will:jarvis:1.0-71"
}
Module Class
public class ExampleModule extends Module {
// Called when the plugin is first loaded
// Used for setting required permissions, registering event handlers, and registering commands
public void initialize() {
// Sets the permissions that the plugin needs, this is used to aggregate permissions for invite links
setNeededPermissions(
Permission.MESSAGE_READ,
Permission.MESSAGE_WRITE
);
// Sets whether the plugin should be enabled by default for new guilds
setDefaultEnabled(false);
// Register our event handler
registerEventHandler(new ExampleEventHandler(this));
// Register our command and what it should be called with
registerCommand("example", new ExampleCommand(this));
}
// Called after the database is initialized and discord is connected
public void finishStartup() {
}
// Called when the plugin is about to be stopped or unloaded
public void stop() {
}
// Called when Jarvis is reloaded
public void reload() {
}
}
ExampleCommand.java
public class ExampleCommand extends Command {
public ExampleCommand(ExampleModule module) {
// Pass command information to superclass
super(
"example", // Command name, what should trigger this command. In this case !example
"example <user mention>", // Command usage
"Displays an example that mentions the specified user", // Command description
module // Module that this command is from
);
}
// The method called when the command is run
// Message is the message that the command was called from
// Args is the message string spliterated
@Override
public void execute(Message message, String... args) {
// Process the command
}
}
ExampleEventHandler.java
public ExampleEventHandler extends EventHandler {
public ExampleEventHandler(ExampleModule module) {
// Pass event handler information to superclass
super(
module, // Module the handler is from
EventPriority.MEDIUM // Event priority. The higher the priority, the sooner it is called
);
// This method is called on every discord event
// Event is the JDA event class
@Override
public void onEvent(Event event) {
// Process the event
}
}
plugin.json
{
"name": "ExamplePlugin",
"main": "com.example.plugin",
"version": "1.0",
"description": "An Example Plugin",
"author": "Me",
"website": "https://example.com"
}