Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Hook into AdditionsPlus

GCNT edited this page Feb 22, 2022 · 2 revisions

APIversionImg

This page is about using the AdditionsPlus API in your own plugin, to either implement the Additions actions in your own plugin, add your own actions or events, or work with other features of this plugin.

Please note, that the examples on this page are only available for AdditionsPlus 2.7.0 as the plugin, and thus the API, was fully remastered in 2.7.0.

First steps

Before you can actually make use of the AdditionsPlus API, you must first import it into your project.

Import with Maven

To import AdditionsPlus, simply add the following code to your pom.xml file.
Replace {VERSION} with the version listed at the top of this page.

<repositories>
    <repository>
        <id>gcnt</id>
        <url>https://nexuslite.gcnt.net/repos/gcnt/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>net.gcnt</groupId>
        <artifactId>additionsplus</artifactId>
        <version>{VERSION}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Import with Gradle

To import AdditionsPlus in your Gradle project, simply add the following code to your Gradle.build file.
Replace {VERSION} with the version listed at the top of this page.

repositories {
    maven {
        url = 'https://nexuslite.gcnt.net/repos/gcnt/'
    }
}

dependencies {
    compileOnly 'net.gcnt:additionsplus:{VERSION}'
}

Set AdditionsPlus as (soft-)depend

The next step is adding AdditionsPlus as a (soft-)dependency in your plugin.yml file, located in the root of your plugin. Whether you add it as a dependency or a soft dependency is on you, depending on if it is optional or not. Not adding AdditionsPlus to the (soft-)depends will most likely cause issues since AdditionsPlus is loaded as one of the last plugins, after world loading.
Please note that the Bukkit resource name is Additions and not AdditionsPlus!

Example Soft Dependency:

name: ExamplePlugin
version: 1.0.0
author: author
main: your.main.class.Here

softdepend: [Additions] # Used when your plugin can run without AdditionsPlus.

Example Hard Dependency:

name: ExamplePlugin
version: 1.0.0
author: author
main: your.main.class.Here

depend: [Additions] # Used when your plugin requires AdditionsPlus to work.

Getting the API class

If you want to access any API methods or classes, you first need to get the main AdditionsPlus plugin class called AdditionsPlugin. In order to get this class, you need to get the JavaPlugin class from Bukkit. For efficiency, you can store this in a variable in your main class. Please do a sanity check first to see if the plugin is actually enabled before working with the API.

The code below shows how to get the plugin class.

AdditionsPlugin additions = (AdditionsPlugin) Bukkit.getPluginManager().getPlugin("Additions");
AdditionsAPI additionsAPI = additions.getAPI();

From here on, you can access every public class that AdditionsPlus has to offer, including adding your own actions, events, and much more.

Clone this wiki locally