[API] CombatX - A simple API for developers icon

[API] CombatX - A simple API for developers -----

A simple Combat Management API for developers



页面 1.png
CombatX
Personally tested version: 1.13, 1.18.2
Theoretically supports: 1.8.9 - 1.20.4

CombatX will make your combat management more concise. We have added various monitoring for player PVP, such as: player entering combat status, combat status duration, player out of combat status, player attacks player event, player quit event during combat, player death event, etc.

About API
I haven't uploaded the API to the Maven central repository yet, in the meantime you can import it as a local dependency into the project.

First you can create the "libs" folder in the project root directory.
Then add the following content in pom.xml
Code (XML):
<dependencies>
    <dependency>
        <groupId>net.sparkomc </groupId>
        <artifactId>combatx </artifactId>
        <version>1.0 </version>
        <scope>system </scope>
        <systemPath>${basedir}/libs/[file name] </systemPath>
    </dependency>
</dependencies>
Please replace [file name] with the jar name you downloaded

API Usage
PlayerCombatStatusEvent - Player enter combat status
PlayerOutOfCombatStatusEvent - Player combat duration expired
PlayerCombatQuitEvent - Player quit game while in combat status

PlayerDiedEvent - Trigger when a player is died
Code (Java):
@EventHandler
public void onDied (PlayerDiedEvent e ) {
    Player player = e. getPlayer ( ) ;
    DamageRecorder recorder = e. getRecorder ( ) ;
       
    // If the player last received damage from a player for more than 10 seconds or the player died unnaturally, the killer will be null
    Player killer = e. getKiller ( ) ;
}

PlayerDamageByPlayerEvent - An event in which a player is harmed by a player. Supports projectile thrown by players.
Code (Java):
@EventHandler
public void onPlayerDamageByPlayer (PlayerDamageByPlayerEvent e ) {
    Player suspect = e. getSuspect ( ) ;
    Player victim = e. getPlayer ( ) ;
}
About DamageRecorder
DamageRecorder is used to record the source and value of the damage received by the player, time, whether it is dead, etc.

Example method:
Code (Java):
public void testMethod ( ) {
    Player player = ... ;
    DamageRecorder recorder = ... ;

    // Damage a player at specified damage (Not physical damage, just record)
    recorder. damage (player, 1.5 ) ;

    // Get the killer of the player.
    // If player is not dead, it will throw IllegalStateException
    // If no one damage him, it will return null
    Player killer = recorder. getKiller ( ) ;

    // Get the assists of the player (not including killer)
    // If player is not dead, it will throw IllegalStateException
    // If no one damage him except the killer, or beside the killer, it will return null
    List <Player > assists = recorder. getAssists ( ) ;

    // Get the total damage of the player got
    double totalDamage = recorder. getTotalDamage ( ) ;

    // Get the damage caused by the specified player to the player
    double damage = recorder. getTotalDamage (killer ) ;

    // Make the player die (Not physical die, just record)
    recorder. die ( ) ;

    // Get whether the player is dead
    boolean died = recorder. isDied ( ) ;

    // Get the timestamp of the last time this player took damage
    long lastDamageTime = recorder. getLastDamageTime ( ) ;
}
About DamageCalculator
To extend your own combat state duration calculation logic, you can:
Code (Java):
public class YourCustomDurationCalculator implements DurationCalculator {
    @Override
    public int calculate (Player suspect ) {
        int duration = Your calculation logic... ;
        return duration ;
    }
}
and then:
Code (Java):
CombatManager. setDurationCalculator ( new YourCustomDurationCalculator ( ) ) ;
About CombatManager
Code (Java):
public void testMethod ( ) {
    Player player = ... ;
       
    // Check if a player is in combat
    boolean combat = CombatManager. isInCombat (player ) ;
       
    // Reset a player's combat record
    CombatManager. resetCombat (player ) ;
       
    // Get the CombatInfo of the player
    CombatInfo info = CombatManager. getCombatInfo (player ) ;
}
About CombatInfo
Code (Java):
public void testMethod ( ) {
    Player player = ... ;

    // Get CombatInfo
    CombatInfo info = CombatManager. getCombatInfo (player ) ;

    // Get the DamageRecorder of a player
    DamageRecorder recorder = info. getRecorder ( ) ;

    // Attack a player (Not physical attack, just record)
    info. attack (VICTIM, 2 ) ;
}


Support
Before reporting a bug, please check that your plugin is up to date, as the issue you are about to report may have been fixed in the latest version.

Please don't report bugs in reviews or you won't get any support!
Please join our
Discord Server to get supports.

Thank for using CombatX!
Resource Information
Author:
----------
Total Downloads: 56
First Release: Mar 3, 2024
Last Update: Mar 3, 2024
Category: ---------------
All-Time Rating:
1 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings