MarketAPI (dla deweloperów)
Publiczne Java API pluginu — odczyt ofert i mutacje wyłącznie z głównego wątku.
Na podstawie kodu GrzybcioRynek 1.0.3 i web 0.1.0.
com.example.marketplace.api.MarketAPI to jedyne publiczne API dla innych pluginów. Inicjalizacja: MarketAPI.init(this) na końcu finishEnable(). HTTP nie istnieje.
Pełna lista metod: Java MarketAPI. Eventy: Eventy.
Gotowość
if (!MarketAPI.isReady()) {
// plugin == null albo !plugin.isEnabled()
}Każda metoda poza isReady() i getCategories() woła ensure():
IllegalStateException: GrzybcioRynek API nie jest gotowegetCategories() zwraca MarketCategory.values() bez ensure() — działa nawet gdy plugin niegotowy.
Mutacje — główny wątek
removeListing(int, Player) i sellItem(Player, ItemStack, double) wołają ensureMainThread():
IllegalStateException: MarketAPI mutacje muszą być wywoływane z głównego wątku serweraOdczyty (getListings, search, getTransaction, …) nie asserują wątku, ale i tak powinny iść z main thread — magazyn nie jest przeznaczony do swobodnego multi-thread.
Mapowanie na rdzeń
| MarketAPI | Implementacja |
|---|---|
getListings() | StorageManager.getAllListings() (kopia listy) |
getListing(int) | StorageManager.getListing |
getListingsBySeller(UUID) | StorageManager.getListingsBySeller |
search(String) | ListingQueryService.query — kategoria ALL, sort NEWEST |
removeListing | MarketManager.removeListing |
sellItem | MarketManager.sellItem (item musi być w ręce) |
getCompletedTransactions() | ExtendedDataStore — tylko COMPLETED |
getTransaction(String) | mapa po UUID-string |
getActiveListingsCount() | StatsManager.getActiveListings() |
getMarketVolume() | StatsManager.getTotalVolume() (suma price zakończonych) |
if (MarketAPI.isReady()) {
MarketListing listing = MarketAPI.getListing(12);
boolean ok = MarketAPI.removeListing(12, admin);
}Nie ma metod: kupno, refund, mailbox, alerty, oceny. To zostaje w MarketManager / serwisach.