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

Interface ShopApi

public interface ShopApi

API interface for interacting with EssentialsC's shop system. The shop system provides GUI-based buying and selling with category organization, stock management, and transaction logging to SQLite.

Retrieve an instance via EssentialsCAPI.getShopApi().

ShopApi shop = APIProvider.getAPI().getShopApi();

shop.getCategory("farming").ifPresent(cat -> {
    player.sendMessage("Category: " + cat.displayName());
});

The ShopCategoryEntry and ShopItemEntry records live in the net.godlycow.org.essc.api.shop sub-package.

Method Summary

boolean isEnabled()
Returns whether the shop system is globally enabled.
List<String> getCategoryIds()
Returns a list of all loaded category IDs.
Optional<ShopCategoryEntry> getCategory(String id)
Returns the category with the given ID, if it exists and is enabled.
List<ShopCategoryEntry> getAllCategories()
Returns all loaded categories.
Optional<ShopItemEntry> getItem(String categoryId, String itemId)
Returns the item from the specified category and item ID.
List<ShopItemEntry> getItemsInCategory(String categoryId)
Returns all items in the specified category.
void openMainShop(Player player)
Opens the main shop menu for the given player.
void openCategory(Player player, String categoryId, int page)
Opens a specific category page for the given player.
CompletableFuture<Boolean> purchase(Player player, String itemId, int amount)
Processes a purchase for the given player (async).
CompletableFuture<Boolean> sell(Player player, String itemId, int amount)
Processes a sale for the given player (async).
void reload()
Reloads all shop configuration from disk.
Method Detail
public boolean isEnabled()

Returns whether the shop system is globally enabled.

Returns:
booleantrue if shops are enabled in config
public List<String> getCategoryIds()

Returns a list of all loaded category IDs.

Returns:
List<String>an unmodifiable list of category IDs; never null
public Optional<ShopCategoryEntry> getCategory(String id)

Returns the category with the given ID, if it exists and is enabled.

Parameters:
idthe category ID; must not be null
Returns:
Optional<ShopCategoryEntry>an Optional containing the category, or empty if not found
public List<ShopCategoryEntry> getAllCategories()

Returns all loaded categories.

Returns:
List<ShopCategoryEntry>an unmodifiable list of categories; never null
public Optional<ShopItemEntry> getItem(String categoryId, String itemId)

Returns the item from the specified category and item ID.

Parameters:
categoryIdthe category ID; must not be null
itemIdthe item ID; must not be null
Returns:
Optional<ShopItemEntry>an Optional containing the item, or empty if not found
public List<ShopItemEntry> getItemsInCategory(String categoryId)

Returns all items in the specified category.

Parameters:
categoryIdthe category ID; must not be null
Returns:
List<ShopItemEntry>an unmodifiable list of items; never null
public void openMainShop(Player player)

Opens the main shop menu for the given player. Displays all enabled categories the player has permission to view.

Warning: Must be called on the main thread.
Parameters:
playerthe player to open the menu for; must not be null
public void openCategory(Player player, String categoryId, int page)

Opens a specific category page for the given player.

Warning: Must be called on the main thread.
Parameters:
playerthe player to open the menu for; must not be null
categoryIdthe category ID to open; must not be null
pagethe page number to open (1-based)
public CompletableFuture<Boolean> purchase(Player player, String itemId, int amount)

Processes a purchase for the given player. Checks permissions, stock, inventory space, and balance before completing the transaction. Sends appropriate messages to the player.

Warning: Do not block the main thread waiting on this future.
Parameters:
playerthe player buying the item; must not be null
itemIdthe item ID to purchase; must not be null
amountthe amount to purchase; must be positive
Returns:
CompletableFuture<Boolean>a future resolving to true if the purchase was successful
public CompletableFuture<Boolean> sell(Player player, String itemId, int amount)

Processes a sale for the given player. Checks inventory for matching items before completing the transaction. Sends appropriate messages to the player.

Warning: Do not block the main thread waiting on this future.
Parameters:
playerthe player selling the item; must not be null
itemIdthe item ID to sell; must not be null
amountthe amount to sell; must be positive
Returns:
CompletableFuture<Boolean>a future resolving to true if the sale was successful
public void reload()

Reloads all shop configuration from disk. Re-reads main.yml and all category files, clearing and rebuilding the category cache. This is equivalent to /shop reload.

Warning: Must be called on the main thread.