API Overview
SigmaOrders provides a comprehensive public API for other plugins to interact with all functionality.
Why Use the API?
The API allows other plugins to:
- Create orders programmatically
- Monitor order activity
- Integrate with custom systems
- Extend functionality
- Build custom GUIs
Getting the API
Method 1: ServicesManager (Recommended)
import com.sigma.orders.api.SigmaOrdersAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.ServicesManager;
public class YourPlugin extends JavaPlugin {
private SigmaOrdersAPI ordersAPI;
@Override
public void onEnable() {
ServicesManager servicesManager = Bukkit.getServicesManager();
ordersAPI = servicesManager.load(SigmaOrdersAPI.class);
if (ordersAPI == null) {
getLogger().warning("SigmaOrders not found! API not available.");
return;
}
getLogger().info("SigmaOrders API loaded! Version: " + ordersAPI.getVersion());
}
}
Method 2: Direct Plugin Access
import com.sigma.orders.SigmaOrders;
import com.sigma.orders.api.SigmaOrdersAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class YourPlugin extends JavaPlugin {
private SigmaOrdersAPI ordersAPI;
@Override
public void onEnable() {
Plugin plugin = Bukkit.getPluginManager().getPlugin("SigmaOrders");
if (plugin == null || !(plugin instanceof SigmaOrders)) {
getLogger().warning("SigmaOrders not found!");
return;
}
SigmaOrders sigmaOrders = (SigmaOrders) plugin;
ordersAPI = sigmaOrders.getAPI();
if (ordersAPI == null) {
getLogger().warning("SigmaOrders API not available!");
return;
}
getLogger().info("SigmaOrders API loaded!");
}
}
API Structure
The API is organized into logical sections:
- Order Management - Create, get, cancel, delete orders
- Item Management - Validate items, check NBT data
- Economy Operations - Balance checks, deposits, withdrawals
- Announcements - Create and broadcast order announcements
- Statistics - Get player order statistics
API Characteristics
Async Operations
Most API methods return CompletableFuture for async operations:
CompletableFuture<Order> future = ordersAPI.createOrder(
playerUuid, playerName, items
);
future.thenAccept(order -> {
if (order != null) {
// Order created successfully
getLogger().info("Order #" + order.getId() + " created!");
} else {
// Order creation failed
getLogger().warning("Failed to create order");
}
});
Thread Safety
- All API methods are thread-safe
- Can be called from any thread
- Database operations are async
- No blocking operations
Error Handling
API methods handle errors gracefully:
- Return
nullorfalseon failure - Log errors internally
- Don't throw exceptions (except for programming errors)
API Methods
Plugin Info
String version = ordersAPI.getVersion();
boolean enabled = ordersAPI.isEnabled();
Order Management
// Create order
CompletableFuture<Order> createOrder(UUID playerUuid, String playerName, List<OrderItem> items);
// Get order
CompletableFuture<Order> getOrder(int orderId);
// Get active orders
CompletableFuture<List<Order>> getActiveOrders();
// Cancel order
CompletableFuture<Boolean> cancelOrder(int orderId, UUID playerUuid);
// Delete order (admin)
CompletableFuture<Boolean> deleteOrder(int orderId);
Delivery & Collection
// Deliver items
CompletableFuture<Boolean> deliverItems(int orderId, int itemId, int amount, UUID delivererUuid, String delivererName);
// Collect items
CompletableFuture<Boolean> collectItems(int orderId, int itemId, int amount, UUID collectorUuid);
Economy
// Check balance
double balance = ordersAPI.getBalance(playerUuid);
// Withdraw
boolean success = ordersAPI.withdrawPlayer(playerUuid, amount);
// Deposit
boolean success = ordersAPI.depositPlayer(playerUuid, amount);
// Format currency
String formatted = ordersAPI.formatCurrency(1000.0);
Dependencies
Add SigmaOrders as a dependency in your pom.xml:
<dependency>
<groupId>com.sigma</groupId>
<artifactId>sigma-orders</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
Or in build.gradle:
dependencies {
compileOnly 'com.sigma:sigma-orders:1.0.2'
}
Version Compatibility
- API Version: Matches plugin version
- Backward Compatibility: Maintained within major versions
- Deprecation: Deprecated methods remain until major version change
Next Steps
- Getting Started - Quick start guide
- Order Management - Order operations
- Item Management - Item operations
- Economy Operations - Economy operations