TaleShop provides a public API for other plugins to integrate with.
Getting the API
TaleShopProviderapi=TaleShopAPI.get();if(api ==null){ // TaleShop is not loadedreturn;}
Sub-APIs
The main TaleShopProvider gives access to four sub-APIs:
API
Description
ShopCatalog
Query and manage categories and items
ShopTransaction
Execute buy/sell operations
AuctionHouse
Create, buy, cancel listings and query mailbox
EconomyAccess
Read-only balance and currency formatting
Shop Catalog
Query and modify the shop programmatically.
ShopCatalogcatalog=api.getShopCatalog();// Get all categoriesList<ShopCategory>categories=catalog.getCategories();// Get items in a categoryList<ShopItem>items=catalog.getItems("tools");// Get a specific itemShopItemitem=catalog.getItem("tools","Tool_Pickaxe_Iron");
Shop Transactions
Execute buy/sell operations on behalf of players.
Auction House
Auction operations are async and return CompletableFuture.
Economy Access
Read-only access to the active economy provider.
Events
TaleShop fires events that other plugins can listen to. Cancellable events can be cancelled to prevent the action.
ShopBuyEvent (Cancellable)
Fired before a player buys an item from the shop.
ShopSellEvent (Cancellable)
Fired before a player sells an item to the shop.
AuctionCreateEvent (Cancellable)
Fired before a player creates an auction listing.
AuctionBuyEvent (Cancellable)
Fired before a player buys an auction listing.
AuctionCancelEvent (Cancellable)
Fired before a player cancels their auction listing.
AuctionExpireEvent
Fired when an auction listing expires. Not cancellable.
ShopTransaction tx = api.getShopTransaction();
// Buy an item for a player
tx.buyItem(player, shopItem, amount);
// Sell an item for a player
tx.sellItem(player, shopItem, amount);
AuctionHouse auction = api.getAuctionHouse();
// Get active listings
CompletableFuture<List<AuctionListing>> listings = auction.getActiveListings();
// Create a listing
auction.createListing(player, itemStack, price);
// Buy a listing
auction.buyListing(player, listingId);
// Cancel a listing
auction.cancelListing(player, listingId);
EconomyAccess economy = api.getEconomyAccess();
// Get player balance
double balance = economy.getBalance(player);
// Check if player can afford something
boolean canAfford = economy.has(player, 100.0);
// Format currency for display
String formatted = economy.format(100.0); // "$ 100"
// Get economy provider name
String name = economy.getEconomyName();
@EventHandler
public void onShopBuy(ShopBuyEvent event) {
Player player = event.getPlayer();
ShopItem item = event.getItem();
int amount = event.getAmount();
BigDecimal totalCost = event.getTotalCost();
// Cancel to prevent the purchase
event.setCancelled(true);
}
@EventHandler
public void onShopSell(ShopSellEvent event) {
Player player = event.getPlayer();
ShopItem item = event.getItem();
int amount = event.getAmount();
BigDecimal totalRevenue = event.getTotalRevenue();
}
@EventHandler
public void onAuctionCreate(AuctionCreateEvent event) {
Player seller = event.getSeller();
ItemStack item = event.getItem();
BigDecimal price = event.getPrice();
}
@EventHandler
public void onAuctionBuy(AuctionBuyEvent event) {
Player buyer = event.getBuyer();
AuctionListing listing = event.getListing();
}
@EventHandler
public void onAuctionCancel(AuctionCancelEvent event) {
Player player = event.getPlayer();
AuctionListing listing = event.getListing();
}