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>
<dependency>
<groupId>net.sparkomc </groupId>
<artifactId>combatx </artifactId>
<version>1.0 </version>
<scope>system </scope>
<systemPath>${basedir}/libs/[file name] </systemPath>
</dependency>
</dependencies>
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 ( ) ;
}
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 ( ) ;
}
public void onPlayerDamageByPlayer (PlayerDamageByPlayerEvent e ) {
Player suspect = e. getSuspect ( ) ;
Player victim = e. getPlayer ( ) ;
}
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 ( ) ;
}
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 ( ) ;
}
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 ;
}
}
@Override
public int calculate (Player suspect ) {
int duration = Your calculation logic... ;
return duration ;
}
}
Code (Java):
CombatManager.
setDurationCalculator
(
new YourCustomDurationCalculator
(
)
)
;
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 ) ;
}
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 ) ;
}
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 ) ;
}
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!
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.8, 1.9, 1.10
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
[API] CombatX - A simple API for developers is a free Minecraft Java mod. Compatible with Minecraft 1.8, 1.9, 1.10, 1.11 and newer. Downloaded 66 times (via Spigot). Download it and open it directly in the game.