Stock API
Purpose
Documentation for EzShops’ Stock API. This page covers the public StockAPI class used to query and manipulate the in-plugin stock market and to manage player holdings.
Obtaining the API
Preferred:
StockAPI stock = EzShopsAPI.getInstance().getStockAPI();
if (!EzShopsAPI.getInstance().isStockAPIAvailable()) {
// stock market features disabled
}
Core capabilities
double getStockPrice(String productId)- get the current market price for a productvoid setStockPrice(String productId, double price)- set/override a product pricevoid updateStockPrice(String productId, int demand)- adjust price due to simulated demandint getPlayerStockAmount(Player player, String productId)- query player holdingsboolean addPlayerStock(Player player, String productId, int amount)- add stock to playerboolean removePlayerStock(Player player, String productId, int amount)- remove stock from playerList<String> getPlayerOwnedStocks(Player player)- list a player’s stock entriesSet<String> getAllProductIds()- list tradable product ids
Thread-safety
StockAPI is documented as thread-safe and safe to call from async contexts. Use async tasks for bulk operations when appropriate.
Example usage
Query and update:
StockAPI stock = EzShopsAPI.getInstance().getStockAPI();
if (stock != null) {
double price = stock.getStockPrice("DIAMOND");
stock.updateStockPrice("DIAMOND", 5); // simulate demand
}
Player holdings:
int amount = stock.getPlayerStockAmount(player, "DIAMOND");
boolean bought = stock.addPlayerStock(player, "DIAMOND", 10);
Source
src/main/java/com/skyblockexp/ezshops/api/StockAPI.java
Notes
- Validate
productIdinputs (non-null, non-empty) before calling; methods throwIllegalArgumentExceptionon invalid input. - When calling
setStockPriceor updating prices, coordinate with server admin policies - programmatic overrides can affect gameplay balance.