Skip to content
Alhxe edited this page Sep 2, 2022 · 10 revisions

Developing with DICore

Do you want to develop your own plugin implementing DICore?

To develop your plugin with DICore you just have to add the DICore Jar to your project. You also have the following options:


Maven

Repository

<repository>
   <id>jitpack.io</id>
   <url>https://jitpack.io</url>
</repository>

Dependency

<dependency>
   <groupId>com.github.Alhxe.Discord-Integration</groupId>
   <artifactId>dicore</artifactId>
   <version>VERSION</version>
   <scope>provided</scope>
</dependency>

Gradle

Repository

maven { url 'https://jitpack.io' }

Dependency

compileOnly 'com.github.Alhxe.Discord-Integration:dicore:VERSION'

The scope of the dependency is important, since if we do not include that provided, it will generate an error. You also need to have the spigot dependency.

Once we have all the dependencies ready, all we need to link the plugin with DICore is to instantiate the object.

/**
* Main Discord Integration Api. When this class is instantiated, the internal
* controller of the core is obtained.
* 
* @param plugin      Plugin from where it is instantiated. The goal is the
*                    logger.
* @param classLoader Class loader.
* @param configFile  True if plugin has config file in DICore folder.
* @param langFile    True if plugin has lang file in DICore folder.
* @throws NoApiException In case the internal controller of the core is not
*                        instantiated, it will throw an error.
*/
DIApi api = new DIApi(plugin, classLoader, configFile, langFile);

Example of DIApi constructor:

DIApi api = new DIApi(plugin, this.getClassLoader(), true, true);
  • api.getInternalController() allows us to access the controller of our plugin, having access to the configuration file (config.yml) and language (lang.yml).

  • api.getCoreController() allows us to access the core controller, having access to the configuration file (config.yml) and language (lang.yml). It also allows us to access the configuration of the bot, or the core plugin.

We also have two other important utilities such as:

  • api.registerDiscordCommand(command) which allows adding discord commands to the bot.
  • api.registerDiscordEvent(api) that allows adding events to the bot.

It is mandatory for it to work well that a config.yml and lang.yml file is added to the resource folder!!

Here I add two examples:

This all works with JDA.

Remember to add DICore as a dependency on plugin.yml.

Clone this wiki locally