Skip to main content

Developer API

FioBlackMarket exposes a Bukkit event API for plugins that need to react when a player successfully buys or sells an item through the Black Market.

Package names

import com.itzfabb.fioblackmarket.api.BlackmarketTransactionType;
import com.itzfabb.fioblackmarket.api.event.BlackmarketTransactionEvent;
import com.itzfabb.fioblackmarket.market.MarketItem;

Transaction event

Listen to BlackmarketTransactionEvent to run custom logic after a successful transaction.

@EventHandler
public void onBlackmarketTransaction(BlackmarketTransactionEvent event) {
Player player = event.getPlayer();
MarketItem item = event.getItem();

if (event.getType() == BlackmarketTransactionType.BUY) {
player.sendMessage("You bought " + event.getAmount() + "x " + item.id());
}
}

The event is fired after the plugin has already:

  • checked market access
  • checked currency provider readiness
  • checked player balance or inventory items
  • updated stock
  • moved money
  • recorded the transaction

This event is not cancellable, so use it for logging, rewards, analytics, hooks, or notifications rather than blocking a transaction.

Event getters

MethodTypeDescription
getPlayer()PlayerPlayer who completed the transaction.
getItem()MarketItemMarket item that was bought or sold.
getType()BlackmarketTransactionTypeTransaction direction: BUY or SELL.
getAmount()intAmount traded in this transaction.
getUnitPrice()doublePrice per unit before multiplying by amount.
getTotalPrice()doubleFinal normalized total price for the full transaction.

Transaction type

public enum BlackmarketTransactionType {
BUY,
SELL
}

Market item data

event.getItem() returns a MarketItem.

Useful accessors:

String id = item.id();
Material material = item.material();
double probability = item.probability();
String name = item.name();
List<String> lore = item.lore();
int amount = item.amount();
double buyPrice = item.buyPrice();
double sellPrice = item.sellPrice();
String currency = item.currency();
int defaultStock = item.defaultStock();
int maxBuyAmount = item.maxBuyAmount();
int maxSellAmount = item.maxSellAmount();
Map<String, List<String>> actions = item.actions();
List<String> commands = item.commands();

Example: log all transactions

@EventHandler
public void onBlackmarketTransaction(BlackmarketTransactionEvent event) {
MarketItem item = event.getItem();

String message = String.format(
"%s %s %dx %s for %.2f",
event.getPlayer().getName(),
event.getType().name().toLowerCase(),
event.getAmount(),
item.id(),
event.getTotalPrice()
);

Bukkit.getLogger().info("[BlackMarket] " + message);
}

Example: reward only buys

@EventHandler
public void onBlackmarketBuy(BlackmarketTransactionEvent event) {
if (event.getType() != BlackmarketTransactionType.BUY) {
return;
}

Player player = event.getPlayer();
double spent = event.getTotalPrice();

if (spent >= 10000) {
player.sendMessage("Thanks for making a large Black Market purchase.");
}
}

plugin.yml advice

For plugins that integrate with FioBlackMarket, add it as a soft dependency:

softdepend:
- FioBlackMarket

If your plugin cannot work without FioBlackMarket, use depend instead:

depend:
- FioBlackMarket

Notes for developers

  • getTotalPrice() is the value after the plugin normalizes currency amount.
  • getUnitPrice() comes from the current dynamic buy or sell price.
  • Buy events use BlackmarketTransactionType.BUY.
  • Sell events use BlackmarketTransactionType.SELL.
  • The event is fired on the Bukkit main thread during inventory interaction handling.