Overview | EssentialsC | AuctionApi
net.godlycow.org.essc.api

Interface AuctionApi

public interface AuctionApi

API interface for interacting with EssentialsC's Auction House system. Retrieve an instance via EssentialsCAPI.getAuctionApi().

AuctionApi ah = APIProvider.getAPI().getAuctionApi();

// list all active auctions
List<Auction> auctions = ah.getActiveAuctions();

// programmatically create a listing
ah.createAuction(player, item, BigDecimal.valueOf(500), 86400000L)
  .thenAccept(success -> {
      if (success) player.sendMessage("Listed!");
  });

Methods that interact with the economy or database return a CompletableFuture and must not be awaited on the main server thread.

Method Summary

List<Auction> getActiveAuctions()
Returns a snapshot of all currently active auctions.
List<Auction> getPlayerAuctions(UUID uuid)
Returns all active auctions listed by the given player.
Optional<Auction> getAuction(int id)
Looks up a single active auction by its database ID.
List<ItemStack> getExpiredItems(UUID uuid)
Returns the cached list of unclaimed expired items for the given player.
boolean hasExpiredItems(UUID uuid)
Returns whether the given player has any unclaimed expired items.
List<SellHistoryEntry> getSellHistory(UUID uuid)
Returns the sell history for the given player, most recent first.
List<BuyHistoryEntry> getBuyHistory(UUID uuid)
Returns the buy history for the given player, most recent first.
CompletableFuture<Boolean> createAuction(Player seller, ItemStack item, BigDecimal price, long duration)
Creates a new auction listing on behalf of the given player.
CompletableFuture<Boolean> buyAuction(Player buyer, int id)
Processes the purchase of an auction by the given player.
CompletableFuture<Boolean> cancelAuction(Player player, int id)
Cancels an active auction and returns the item to the seller's expired-items queue.
boolean claimExpiredItems(Player player)
Claims all expired items for the given player, delivering them to their inventory.
Method Detail
public List<Auction> getActiveAuctions()

Returns a snapshot of all currently active (non-expired, non-claimed) auctions.

The returned list is not backed by the internal auction map — modifications to it have no effect on the Auction House. The order of entries is not guaranteed.

Returns:
List<Auction>a list of active auctions; never null, may be empty
public List<Auction> getPlayerAuctions(UUID uuid)

Returns all active auctions listed by the given player.

Returns an empty list if the player has no active listings. The returned list is not backed by internal state.

Parameters:
uuidthe UUID of the seller; must not be null
Returns:
List<Auction>the player's active listings; never null, may be empty
public Optional<Auction> getAuction(int id)

Looks up a single active auction by its database ID.

Parameters:
idthe auction ID to look up
Returns:
Optional<Auction>an Optional containing the auction if found and still active, or Optional.empty() if the ID is unknown or the auction has already been claimed or expired
public List<ItemStack> getExpiredItems(UUID uuid)

Returns the cached list of unclaimed expired items for the given player.

Items appear here when an auction expires without a buyer or is cancelled. The list is loaded from the database on player join and kept in memory until the player claims their items or disconnects. The returned list is a copy.

Only items for currently online players are guaranteed to be cached. For offline players the list will typically be empty even if unclaimed items exist in the database.

Parameters:
uuidthe UUID of the player; must not be null
Returns:
List<ItemStack>items awaiting claim; never null, may be empty
public boolean hasExpiredItems(UUID uuid)

Returns whether the given player has any unclaimed expired items waiting.

Equivalent to checking !getExpiredItems(uuid).isEmpty() but avoids allocating the list copy. Subject to the same online-only caching caveat as getExpiredItems(UUID).

Parameters:
uuidthe UUID of the player; must not be null
Returns:
booleantrue if the player has at least one item awaiting claim; false if the cache is empty or the player is offline
public List<SellHistoryEntry> getSellHistory(UUID uuid)

Returns the sell history for the given player, most recent entry first.

The history is kept in memory and automatically capped at 100 entries per player. Returns an empty list if no sales have been recorded yet for this player, or if the player has never been online since the server started.

Parameters:
uuidthe UUID of the seller; must not be null
Returns:
List<SellHistoryEntry>sell history records; never null, may be empty
public List<BuyHistoryEntry> getBuyHistory(UUID uuid)

Returns the buy history for the given player, most recent entry first.

The history is kept in memory and automatically capped at 100 entries per player. Returns an empty list if no purchases have been recorded yet for this player, or if the player has never been online since the server started.

Parameters:
uuidthe UUID of the buyer; must not be null
Returns:
List<BuyHistoryEntry>buy history records; never null, may be empty
public CompletableFuture<Boolean> createAuction(Player seller, ItemStack item, BigDecimal price, long duration)

Creates a new auction listing on behalf of the given player.

Before inserting into the database, the following check is performed:

  • The seller's current active listing count is compared against the configured maximum. This check is bypassed if the player holds the essentialsc.ah.bypass.limit permission.

The provided ItemStack is cloned internally — you may safely modify or discard the original after this call.

Do not block the main thread waiting on this future.

Parameters:
sellerthe player creating the listing; must not be null
itemthe item to list; must not be null
pricethe buy-now price; must be positive, must not be null
durationthe auction duration in milliseconds; must be positive
Returns:
CompletableFuture<Boolean>true if the auction was created successfully, false if the player is at their listing limit or the database insert failed
public CompletableFuture<Boolean> buyAuction(Player buyer, int id)

Processes the purchase of an auction by the given player.

The future resolves to false and no action is taken if any of the following conditions are met:

  • The auction ID does not exist or is already claimed/expired.
  • The buyer is the seller of the auction.
  • The buyer does not have sufficient funds.
  • The auction is already being processed by a concurrent request.

On success: the buyer is charged, the item is delivered to their inventory (dropped at their feet if the inventory is full), the seller receives payment, and the auction is marked as claimed and removed from active listings.

Do not block the main thread waiting on this future.

Parameters:
buyerthe player purchasing the auction; must not be null
idthe ID of the auction to buy
Returns:
CompletableFuture<Boolean>true on a successful purchase, false otherwise
public CompletableFuture<Boolean> cancelAuction(Player player, int id)

Cancels an active auction and returns the item to the seller's expired-items queue.

The future resolves to false and no action is taken if any of the following conditions are met:

  • The auction ID does not exist in the active listings.
  • The requesting player is not the seller and does not have the essentialsc.ah.admin permission.
  • The auction is already being processed by a concurrent request.

On success, the cancelled item is placed in the seller's expired-items queue and persisted to the database. The seller can retrieve it via claimExpiredItems(Player).

Do not block the main thread waiting on this future.

Parameters:
playerthe player requesting cancellation; must not be null
idthe ID of the auction to cancel
Returns:
CompletableFuture<Boolean>true if the auction was cancelled, false otherwise
public boolean claimExpiredItems(Player player)

Claims all expired items for the given player, delivering them to their inventory.

Items that do not fit in the player's inventory are dropped naturally at their current location. If a claim operation is already in progress for this player (concurrent guard), this method returns false immediately without delivering anything.

This method is synchronous and safe to call on the main thread.

Parameters:
playerthe player claiming their expired items; must not be null
Returns:
booleantrue if at least one item was found and delivered, false if the player had no expired items or a claim was already in progress