API Installation
API Installation for BlanketEconomy
Step-by-Step Guide
Download the Latest Release: Visit the Releases page and download the latest version of the BlanketEconomy API.
Place the
.jar
File: Copy the downloaded.jar
file and place it into your Minecraft server'smods
folder.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
.jar
to Your ProjectDownload the Latest Version: Get the latest version of BlanketEconomy from Modrinth.
Create a
libs
Folder: Inside your project, create a folder namedlibs
.Add the File to
libs
: Place the downloaded.jar
file into thelibs
folder.Add Dependencies: Add the dependency to your build script (e.g., in
build.gradle
for a Gradle project).
Example (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:
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:
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:
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:
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:
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:
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:
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:
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:
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.
Last updated