# API

### Adding the DeluxeCombat API via Gradle / Maven

First, you have to make sure that you have added the jitpack.io repository in your build.gradle:

```
<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>
```

After that, simply add the DeluxeCombatAPI library.

```
<dependency>
  <groupId>com.github.timderspieler</groupId>
  <artifactId>DeluxeCombat-API</artifactId>
  <version>VERISON</version>
  <scope>provided</scope>
</dependency>
```

The current version is: ![](https://jitpack.io/v/timderspieler/DeluxeCombat-API.svg)

### Check if DeluxeCombat is installed

To prevent errors, we need to check if DeluxeCombat is installed.

```
if (Bukkit.getPluginManager().getPlugin("DeluxeCombat") != null) {
    // YOUR CODE HERE
}
```

### Initializing an API object

To use the api, we need to create an API object. Its as simple as following:

```
DeluxeCombatAPI api = new DeluxeCombatAPI();
```

### Methods

```
// Void Methods:       (Execute an action)

void addPoints(Player p, int points); // Adds points to a player
void removePoints(Player p, int points); // Removes points from a player
void untag(Player p); // Untags a player
void togglePvP(Player p, boolean status); // Toggles the pvp of a player
void removeBounty(Player p); // Removes the bounty of a player
void createBounty(Player target, Player initiator, boolean anonymous, double bounty, boolean removeTax); // Creates a bounty

// Integer Methods:    (Return an integer value)

int getRemainingCombatTime(Player p); // Returns how many sec the player is still in combat
int getHighestKillStreak(Player p); // Returns the highest killstreak of a player
int getStreak(Player p); // Returns the streak the player in his current session has
int getCombatlogs(Player p); // Returns the amount of combatlogs a player has
int getDeaths(Player p); // Returns the amount of deaths a player has
int getKills(Player p); // Returns the amount of kills a player has
int getPoints(Player p); // Returns the amount of points a player has


// Double Methods:     (Return a double value)

double getKD(Player p); // Returns the kd of a player


// Boolean Methods:    (Return true or false)

boolean isInCombat(Player p); // Returns if the player is in a combat
boolean hasProtection(Player p); // Returns if the player has an active protection
boolean hasPvPEnabled(Player p); // Returns if the player has pvp enabled
boolean hasBounty(Player p); // Returns if there is a bounty on a player


// Player Methods:     (Return a player object)

Player getCurrentOpponent(Player p); // Returns the current combat oppenent of a player
```

### Events

You can listen to these events in your plugin.

#### Combatlog Event

Gets fired, when a player quits a fight early.

```
@EventHandler
public void onCombatLog(CombatlogEvent e) {

    // Your code here

}
```

#### CombatStateChange Event

Gets fired, if the combat state of a player changes (tagged and untagged).

```
@EventHandler
public void onCombatStateChange(CombatStateChangeEvent e) {

    // Your code here
    
}
```

```
e.getState(); // Returns the combat state: CombatState.TAGGED or CombatState.UNTAGGED
```

#### PlayerTogglePVPEvent

Gets fired, if the player toggles their pvp.

```
@EventHandler
public void onPvPToggle(PlayerTogglePVPEvent e) {

    // Your code here
    
}
```

#### EntityCombatlogEvent

Gets fired, if the player quits the fight early in a fight with an entity. Can be cancelled.

```
@EventHandler
public void onEntityCombatlog(EntityCombatlogEvent e) {

    // Your code here
    
}
```

#### BountyInitiateEvent

Gets fired, if a bounty is about to get initiated. Can be cancelled.

```
@EventHandler
public void onBountyCreate(BountyInitiateEvent e) {

    // Your code here
    
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://timderspieler.gitbook.io/timderspieler-plugins/deluxecombat/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
