GrzybcioRynek

MarketAPI (dla deweloperów)

Publiczne Java API pluginu — odczyt ofert i mutacje wyłącznie z głównego wątku.

Kompatybilne z: GrzybcioRynek 1.0.3Minecraft 26.2Web 0.1.0

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ść

java
if (!MarketAPI.isReady()) {
    // plugin == null albo !plugin.isEnabled()
}

Każda metoda poza isReady() i getCategories() woła ensure():

text
IllegalStateException: GrzybcioRynek API nie jest gotowe

getCategories() 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():

text
IllegalStateException: MarketAPI mutacje muszą być wywoływane z głównego wątku serwera

Odczyty (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ń

MarketAPIImplementacja
getListings()StorageManager.getAllListings() (kopia listy)
getListing(int)StorageManager.getListing
getListingsBySeller(UUID)StorageManager.getListingsBySeller
search(String)ListingQueryService.query — kategoria ALL, sort NEWEST
removeListingMarketManager.removeListing
sellItemMarketManager.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)
Example
java
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.