MarketAPI (for developers)
Public Java plugin API — listing reads and mutations only from the main thread.
Based on GrzybcioRynek 1.0.3 and web 0.1.0 source.
com.example.marketplace.api.MarketAPI is the only public API for other plugins. Init: MarketAPI.init(this) at the end of finishEnable(). HTTP does not exist.
Full method list: Java MarketAPI. Events: Events.
Readiness
if (!MarketAPI.isReady()) {
// plugin == null or !plugin.isEnabled()
}Every method except isReady() and getCategories() calls ensure():
IllegalStateException: GrzybcioRynek API nie jest gotowegetCategories() returns MarketCategory.values() without ensure() — works even when the plugin is not ready.
Mutations — main thread
removeListing(int, Player) and sellItem(Player, ItemStack, double) call ensureMainThread():
IllegalStateException: MarketAPI mutacje muszą być wywoływane z głównego wątku serweraReads (getListings, search, getTransaction, …) do not assert the thread, but should still run on the main thread — storage is not meant for free multi-threading.
Mapping to the core
| MarketAPI | Implementation |
|---|---|
getListings() | StorageManager.getAllListings() (list copy) |
getListing(int) | StorageManager.getListing |
getListingsBySeller(UUID) | StorageManager.getListingsBySeller |
search(String) | ListingQueryService.query — category ALL, sort NEWEST |
removeListing | MarketManager.removeListing |
sellItem | MarketManager.sellItem (item must be in hand) |
getCompletedTransactions() | ExtendedDataStore — only COMPLETED |
getTransaction(String) | map by UUID-string |
getActiveListingsCount() | StatsManager.getActiveListings() |
getMarketVolume() | StatsManager.getTotalVolume() (sum of completed price) |
if (MarketAPI.isReady()) {
MarketListing listing = MarketAPI.getListing(12);
boolean ok = MarketAPI.removeListing(12, admin);
}No methods for: buy, refund, mailbox, alerts, ratings. Those stay in MarketManager / services.