API For Developers - bruno-medeiros1/elytra-essentials GitHub Wiki
ElytraEssentials provides a simple and powerful API that allows other plugins to interact with its features. To use the API, you need to add ElytraEssentials as a dependency to your project. This is easily done using JitPack.
Add the JitPack repository and the ElytraEssentials dependency to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.bruno-medeiros1</groupId>
<artifactId>ElytraEssentials</artifactId>
<version>v1.9.1</version> <!-- Replace with the desired release tag -->
<scope>provided</scope>
</dependency>
</dependencies>
Add the JitPack repository and the ElytraEssentials dependency to your build.gradle
:
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compileOnly 'com.github.bruno-medeiros1:ElytraEssentials:v1.9.1' // Replace with the desired release tag
}
Important
You must use <scope>provided</scope>
(for Maven) or compileOnly
(for Gradle). This ensures that ElytraEssentials is not bundled inside your plugin's JAR file.
After adding the dependency, you need to get the API instance from Bukkit's ServicesManager. It's best to do this in your plugin's onEnable() method.
import org.bruno.elytraEssentials.api.ElytraEssentialsAPI;
import org.bukkit.plugin.RegisteredServiceProvider;
public class YourPlugin extends JavaPlugin {
private ElytraEssentialsAPI elytraApi;
@Override
public void onEnable() {
if (!setupElytraEssentialsAPI()) {
getLogger().severe("ElytraEssentials API not found! This plugin requires ElytraEssentials to function.");
getServer().getPluginManager().disablePlugin(this);
return;
}
// You can now use the API!
getLogger().info("Successfully hooked into the ElytraEssentials API.");
}
private boolean setupElytraEssentialsAPI() {
RegisteredServiceProvider<ElytraEssentialsAPI> provider = getServer().getServicesManager().getRegistration(ElytraEssentialsAPI.class);
if (provider != null) {
this.elytraApi = provider.getProvider();
}
return this.elytraApi != null;
}
// Example of using the API
public void checkPlayerFlightTime(Player player) {
if (this.elytraApi == null) return;
int flightTime = elytraApi.getFlightTime(player.getUniqueId());
String activeEffect = elytraApi.getActiveEffectKey(player.getUniqueId());
player.sendMessage("Your flight time is: " + flightTime + " seconds.");
if (activeEffect != null) {
player.sendMessage("Your active effect is: " + activeEffect);
}
}
}