Developer API
Add Storefront as a softdepend in your plugin.yml and compile against the Storefront JAR.
Purchase event
StorefrontPurchaseEvent fires after every paid purchase, on the buyer's thread. It is informational: the purchase already happened. getSource() is shop, daily, reroll or regear.
import com.andrey.storefront.api.StorefrontPurchaseEvent;
@EventHandler
public void onPurchase(StorefrontPurchaseEvent event) {
Player player = event.getPlayer();
getLogger().info(player.getName() + " bought " + event.getQuantity() + "x "
+ event.getItemId() + " from " + event.getSource()
+ " for " + event.getPrice() + " " + event.getCurrency());
}Shards
| Method | Result |
|---|---|
StorefrontAPI.isReady() | True while Storefront is enabled and licensed. |
getCachedShards(uuid) | Last known balance of an online player, without touching the database. |
getShards(uuid) | CompletableFuture<Long> read from the database (offline players too). |
giveShards(uuid, name, amount, reason) | CompletableFuture<Boolean>; false if not ready, amount ≤ 0 or over the maximum. |
takeShards(uuid, name, amount, reason) | CompletableFuture<Boolean>; only takes shards if the player has enough. |
import com.andrey.storefront.api.StorefrontAPI;
if (StorefrontAPI.isReady()) {
StorefrontAPI.giveShards(player.getUniqueId(), player.getName(), 50, "quest")
.thenAccept(ok -> getLogger().info("Paid: " + ok));
}Threads
The futures complete off the main thread. Schedule back to the player (or the region scheduler on Folia) before touching the world or inventories. The
reason is saved in the shard log (up to 24 characters).