# API Installation

## API Installation for BlanketEconomy

### Step-by-Step Guide

1. **Download the Latest Release**:\
   Visit the [Releases](https://github.com/krripe/BlanketEconomy/releases) page and download the latest version of the **BlanketEconomy** API.
2. **Place the `.jar` File**:\
   Copy the downloaded `.jar` file and place it into your Minecraft server's `mods` folder.
3. **Start Your Server**:\
   Run your server to generate the configuration file at `config/blanketeconomy/config.json`. This file can be modified to customize the API behavior.

***

## Adding BlanketEconomy as a Dependency

#### How to Add the `.jar` to Your Project

1. **Download the Latest Version**:\
   Get the latest version of **BlanketEconomy** from [Modrinth](https://modrinth.com/mod/blanketeconomy).
2. **Create a `libs` Folder**:\
   Inside your project, create a folder named `libs`.
3. **Add the File to `libs`**:\
   Place the downloaded `.jar` file into the `libs` folder.
4. **Add Dependencies**:\
   Add the dependency to your build script (e.g., in `build.gradle` for a Gradle project).

#### Example (Groovy):

```groovy
dependencies {
    modImplementation(files("libs/blanketeconomy-x.x.x.jar"))
}
```

This ensures that your project includes **BlanketEconomy** as a dependency.

***

### Imports and Initializing the API

To use the **BlanketEconomy** API in your code, import the following:

```java
import org.blanketeconomy.api.BlanketEconomyAPI;
import org.blanketeconomy.api.EconomyAPI;
import org.blanketeconomy.utils.CustomColorParser;
```

#### Accessing the API:

To initialize and access the **BlanketEconomy** API, use the following code:

```java
val api = BlanketEconomy.getAPI();
```

This will give you access to various economy-related methods, such as getting balances, transferring currency, and managing custom currencies.

***

### Code Examples for Using the API

#### 1. **Getting a Player's Balance**

To retrieve the balance of a specific player for a given currency:

```java
UUID playerId = player.getUUID();
BigDecimal balance = api.getBalance(playerId, "gold_coin");
System.out.println("Player's balance: " + balance);
```

#### 2. **Setting a Player's Balance**

To set the balance for a player:

```java
UUID playerId = player.getUUID();
BigDecimal newBalance = new BigDecimal("500");
api.setBalance(playerId, newBalance, "gold_coin");
```

#### 3. **Adding Currency to a Player's Balance**

To add currency to a player’s balance:

```java
UUID playerId = player.getUUID();
BigDecimal amountToAdd = new BigDecimal("100");
api.addBalance(playerId, amountToAdd, "gold_coin");
```

#### 4. **Subtracting Currency from a Player's Balance**

To subtract currency from a player’s balance:

```java
UUID playerId = player.getUUID();
BigDecimal amountToSubtract = new BigDecimal("50");
boolean success = api.subtractBalance(playerId, amountToSubtract, "gold_coin");

if (success) {
    System.out.println("Successfully subtracted from balance.");
} else {
    System.out.println("Insufficient funds.");
}
```

#### 5. **Transferring Currency Between Players**

To transfer currency from one player to another:

```java
UUID fromPlayerId = sender.getUUID();
UUID toPlayerId = receiver.getUUID();
BigDecimal amountToTransfer = new BigDecimal("200");

boolean success = api.transfer(fromPlayerId, toPlayerId, amountToTransfer, "gold_coin");

if (success) {
    System.out.println("Transfer successful.");
} else {
    System.out.println("Transfer failed.");
}
```

#### 6. **Checking if a Player Has Enough Funds**

To check if a player has sufficient funds:

```java
UUID playerId = player.getUUID();
BigDecimal requiredAmount = new BigDecimal("300");

boolean hasEnough = api.hasEnoughFunds(playerId, requiredAmount, "gold_coin");

if (hasEnough) {
    System.out.println("Player has enough funds.");
} else {
    System.out.println("Player does not have enough funds.");
}
```

#### 7. **Creating a New Currency**

To create a new custom currency in the game:

```java
String name = "Diamond Coin";
String lore = "A shiny and valuable currency";
String material = "minecraft:diamond";
int customModelData = 1234;
BigDecimal startingBalance = new BigDecimal("100");
String symbol = "D";

boolean isPrimary = false;  // Set to true if this should be the primary currency

boolean success = api.createCurrency(name, lore, material, customModelData, startingBalance, symbol, isPrimary);

if (success) {
    System.out.println("Currency created successfully.");
} else {
    System.out.println("Failed to create currency.");
}
```

***

These examples provide a starting point for integrating the **BlanketEconomy** API into your mod. From managing player balances to creating custom currencies, the API is flexible and powerful, making it easy to implement your economy needs.
