Skip to content

🌐 Plugin Creation

Fran2019 edited this page May 27, 2024 · 17 revisions

πŸ“¦ About 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");
    }
}
πŸ“ƒ 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();
    }
}
πŸ“ƒ 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

πŸ’Ύ Example Template

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.

🧭 Navigation Menu

🏠 General

Clone this wiki locally