-
Notifications
You must be signed in to change notification settings - Fork 1
π Plugin Creation
The following documentation describes the essential components required for the creation and normal functioning of a plugin. This includes registering the plugin, starting it, and handling commands. Additionally, knowledge of JDA (Java Discord API) is essential for interacting with Discord.
π Main.java (i.fran2019.Test.Main)
The Main.java
file defines the main class of the plugin, which extends from a base Plugin
class. This class is responsible for initializing the plugin and managing its lifecycle, such as enabling and disabling the plugin.
package i.fran2019.Test;
import i.fran2019.BotMaster.API.implementations.Plugin;
import i.fran2019.BotMaster.BotMaster;
import i.fran2019.Test.Commands.TestCMD;
import lombok.Getter;
@Getter
public class Test extends Plugin {
// Reference to the current instance of the plugin
private final Test test = this;
// Constructor to initialize the plugin with its name and description
public Test(BotMaster botMaster, String name, String description) {
super(botMaster, name, description);
}
// Called when the plugin is enabled
@Override
public void onEnable() {
// Registering the command with the command manager
getBotMaster().getCommandManager().registerCommand(new TestCMD("test2" /* Command Name */));
// Logging that the plugin has been loaded
getLogger().info("Plugin Loaded");
}
// Called when the plugin is disabled
@Override
public void onDisable() {
// Logging that the plugin has been disabled
getLogger().info("Plugin Disabled");
}
}
π bot.yml (Resources Folder)
The bot.yml
file is a configuration file in YAML format that contains basic information about the plugin. This file is used by the system to load and identify the plugin.
main: i.fran2019.Test.Test
name: TestPlugin
description: TestDescription
version: 1.0.1
For creating new commands, use this straightforward template that extends Command and includes all key methods for adding options and handling events with ease.
π TestCMD.java (i.fran2019.Test.Commands.TestCMD)
The TestCMD.java
file defines a specific command for the plugin. Commands are functionalities that users can execute.
package i.fran2019.Test.Commands;
import i.fran2019.BotMaster.API.annotations.CommandOption;
import i.fran2019.BotMaster.API.implementations.Command;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
public class TestCMD extends Command {
// Constructor to initialize the command with its name
public TestCMD(String name) {
super(name);
}
// Creating a new command option with predefined choices
@CommandOption(
name = "Option1",
description = "useless",
required = true,
type = OptionType.STRING,
choices = {"Test|test", "Test2|test2", "Test4"}
)
String option1;
// Logic to be executed when the command is run
@Override
public void onExecute(SlashCommandInteractionEvent e) {
// Sending a response message to the user
e.reply("Hello from the Test command! Output: " + option1).queue();
}
}
For a full example template, refer to the BotMaster-TestPlugin repository.
By following this documentation, you can ensure that your plugin is correctly registered, starts properly, and handles commands efficiently.
Support: Discord