EternalCombat API
As part of open-source community, we support developers who want to create their own plugins using our API. We provide a simple and easy to use API that allows you to create your own plugins using our API.
📚 Dependency Management
To use our work in your plugin, You need to install correct artifact for your project. Our plugin supports Maven, Gradle Kotlin, Gradle Groovy and SBT. To use latest release check maven repository.
Add repository:
maven("https://repo.eternalcode.pl/releases")
maven { url = "https://repo.eternalcode.pl/releases" }
<repository>
<id>eternalcode-reposilite-releases</id>
<name>EternalCode Repository</name>
<url>https://repo.eternalcode.pl/releases</url>
</repository>
Add dependency:
compileOnly("com.eternalcode:eternalcombat-api:1.1.1")
compileOnly("com.eternalcode:eternalcombat-api:1.1.1")
<dependency>
<groupId>com.eternalcode</groupId>
<artifactId>eternalcombat-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
You must also add dependency inside plugin.yml
or paper-plugin.yml
file, this is required to load our plugin before your plugin, so they can access our API.
depend: [EternalCombat]
dependencies:
server:
EternalCombat:
load: OMIT
required: true
join-classpath: true
DANGER
⚠️ Remember to add dependency inside plugin.yml
or paper-plugin.yml
file, otherwise your plugin will not work! ⚠️
📝 Usage
To use our API you need to create instance of EternalCombatAPI
class. You can do it by using EternalCombatAPI.getInstance()
method.
EternalCombatAPI eternalCombatApi = EternalCombatProvider.provide();
After creating instance of api, the User gets access to various classes used in our plugin and methods. Our API includes:
Class | Provide method |
---|---|
FightManager | getFightManager() |
RegionProvider | getRegionProvider() |
FightPearlManager | getFightPearlManager() |
FightTagOutService | getFightTagOutService() |
FightEffectService | getFightEffectService() |
DropManager | getDropManager() |
DropKeepInventoryManager | getDropKeepInventoryManager() |
PluginConfig | getPluginConfig() |
FightManager usage examples
The User can then use the methods of the given classes to create their own use cases. Here is an example how to obtain instance of FightManager
:
public class YourPlugin extends JavaPlugin {
private EternalCombatApi eternalCombatApi;
private FightManager fightManager;
@Override
public onEnable() {
this.eternalCombatApi = EternalCombatProvider.provide();
this.fightManager = eternalCombatApi.getFightManager();
}
}
Then pass down the FightManager
to your classes. After that You can use examples shown below.
Check if the player is in combat by using FightManager
class. Example:
if (fightManager.isInCombat(player.getUniqueId())) {
// player is in combat
}
Tag player who is not already in the combat using FightManager
class. Example:
if (!fightManager.isInCombat(player.getUniqueId())) {
fightManager.tag(player.getUniqueId(), Duration.of(10, ChronoUnit.SECONDS), CauseOfTag.COMMAND);
FightTag fightTag = fightManager.getTag(player.getUniqueId());
// tag player
}
Event base API
Our plugin supports two types of events. The first type is the FightTagEvent
that is called when the player enters the fight or extends duration of the fight. The second type is the FightUnTagEvent
that is called when the player leaves the fight.
You can access both event types by using @EventHandler
. In example below we check why the player was untagged.
@EventHandler
public void onUnTag(FightUntagEvent event) {
CauseOfUnTag cause = event.getCause();
if (cause == CauseOfUnTag.DEATH) {
Bukkit.getPlayer(event.getPlayer()).sendMessage("You died!");
}
}