> For the complete documentation index, see [llms.txt](https://edseries-plugins.gitbook.io/p/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edseries-plugins.gitbook.io/p/edcoinflip/reference/developer-api.md).

# Developer API

Everything is in `es.edwardbelt.edcoinflip.api`. Add EdCoinflip as a `softdepend` and the jar as a provided dependency. Call it on the main thread.

```java
if (EdCoinflipAPI.isAvailable()) {
    List<CoinflipInfo> open = EdCoinflipAPI.getOpenCoinflips();          // in the list's order
    List<CoinflipInfo> mine = EdCoinflipAPI.getOpenCoinflips(player.getUniqueId());
    CoinflipInfo one = EdCoinflipAPI.getCoinflip(12);                      // null when gone
    List<String> currencies = EdCoinflipAPI.getCurrencies();               // usable currency ids
    boolean watching = EdCoinflipAPI.isInFlip(player.getUniqueId());
    EdCoinflipAPI.openMenu(player);
    EdCoinflipAPI.cancel(12);                                               // refunds the creator
    String text = EdCoinflipAPI.format("money", new BigDecimal("1500"));    // "1,500"
}
```

`CoinflipInfo` (record): `id`, `creator`, `creatorName`, `currency`, `amount` (each player's bet), `createdAt`.

## Events

| Event                 | Cancellable | When                                                                                                                           |
| --------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `CoinflipCreateEvent` | yes         | a player is about to create a coinflip; every check passed, the bet is not taken yet (`getPlayer`, `getCurrency`, `getAmount`) |
| `CoinflipJoinEvent`   | yes         | a player is about to join; the bet is not taken and the winner not picked (`getPlayer`, `getCoinflip`)                         |
| `CoinflipResultEvent` | no          | the coinflip was decided (`getWinner`, `getWinnerName`, `getLoser`, `getLoserName`, `getPot`, `getTax`, `getWin`)              |
| `CoinflipCancelEvent` | no          | an open coinflip was refunded; `getCause()` is `cancelled`, `expired` or `admin`                                               |

A cancelled create or join sends no message: tell the player why yourself.
