Dependency
Add the MineDuels API to your plugin's build and plugin.yml.
Compile against the API jar only. Do not compile against the plugin jar (MineDuels-0.10.0.jar): it contains internals that change between versions. The API jar holds just the service interface, the snapshot records and the events.
| File | Contains | Use it for |
|---|---|---|
MineDuels-API-0.10.0.jar | dev.mineduels.api.* | Compiling your plugin |
MineDuels-API-0.10.0-sources.jar | The same with Javadoc | Your IDE, for documentation |
MineDuels-0.10.0.jar | The plugin, which also contains the API classes | Running on the server |
At runtime your plugin uses the API classes from the MineDuels plugin, so do not shade the API jar into yours.
Get the jar
Build it from the source (see Build from source):
./gradlew :api:jar :api:sourcesJar
ls api/build/libsMineDuels-API-0.10.0.jar
MineDuels-API-0.10.0-sources.jarCopy the jar into your project, for example into libs/.
Gradle (Kotlin DSL)
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
compileOnly(files("libs/MineDuels-API-0.10.0.jar"))
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}compileOnly keeps the API out of your jar.
Gradle (Groovy)
dependencies {
compileOnly 'io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT'
compileOnly files('libs/MineDuels-API-0.10.0.jar')
}Maven
Install the jar into your local repository once:
mvn install:install-file -Dfile=MineDuels-API-0.10.0.jar \
-DgroupId=dev.mineduels -DartifactId=mineduels-api -Dversion=0.10.0 -Dpackaging=jar<dependency>
<groupId>dev.mineduels</groupId>
<artifactId>mineduels-api</artifactId>
<version>0.10.0</version>
<scope>provided</scope>
</dependency>plugin.yml
If your plugin cannot work without MineDuels:
name: MyPlugin
main: com.example.MyPlugin
version: 1.0
api-version: '1.21'
depend: [MineDuels]MineDuels loads first, and your plugin is not enabled when it is missing.
If MineDuels is optional:
softdepend: [MineDuels]Then check for it before touching any MineDuels class:
if (Bukkit.getPluginManager().isPluginEnabled("MineDuels")) {
MineDuelsApi api = Bukkit.getServicesManager().load(MineDuelsApi.class);
// use api
}Keep every reference to dev.mineduels.api classes in code that only runs after that check, for example in a separate class. A class that mentions an API type in a field or method signature fails to load when MineDuels is absent.
final class DuelsHook {
private final MineDuelsApi api;
DuelsHook(MineDuelsApi api) {
this.api = api;
}
int elo(Player player, String kit) {
return api.elo(player.getUniqueId(), kit).orElse(-1);
}
}// in your main class
private DuelsHook hook;
@Override
public void onEnable() {
if (Bukkit.getPluginManager().isPluginEnabled("MineDuels")) {
hook = new DuelsHook(Bukkit.getServicesManager().load(MineDuelsApi.class));
}
}Folia
If your plugin supports Folia, add folia-supported: true to its plugin.yml. MineDuels itself supports Folia. See Threads and Folia.
Checking it works
Start the server and run /plugins. MineDuels and your plugin should both be green. A ClassNotFoundException for dev.mineduels.api... means MineDuels is not installed or not enabled, or you shaded an old copy of the API into your jar.