基本的な概念

Sponge の経済 API は開発者が知っておくべきいくつかの要素があります:

  • EconomyService

  • 通貨(Currency)

  • 口座(Account)

  • トランザクション

EconomyService

EconomyService は経済 API の基礎となります。これを用いて経済 API を使用したり、通貨や口座管理の手段を提供したりします。

警告

Sponge does not provide a default implementation for the EconomyService. It’s completely up to plugins to implement the Economy API. This means that you have to rely on another plugin which implements the service or you’ll have to implement it yourself, if you want to make use of it.

通貨(Currency)

The Currency object represents a form of Currency. Currency stores a display name (plural and singular), a symbol, the amount of fractional digits, and whether the currency is the default currency for the economy. If the economy plugin chooses, it can support multiple currencies.

口座(Account)

Account は特定のプレイヤーや他のオブジェクト(銀行や会社、エンティティ)についての情報を保存するために使われます。 Sponge の経済 API では2種類の口座タイプがあります:

バーチャルアカウント

バーチャルアカウントは文字列として保存されている識別子と紐付けられます。バーチャルアカウントはだいたいすべてのものと紐付けることができますが、銀行もしくはプレイヤーでないものに広く使われます。getIdentifier() でバーチャルアカウントの識別子を取得できます。

ユニークアカウント

ユニークアカウントは UUID (通常はプレイヤー)と結び付けられています。 getUUID() でユニークアカウントの UUID を取得できます。

トランザクション

トランザクションは口座の残高の変化を表現します。トランザクションには3タイプあります:

  • Deposit: Occurs when an account has funds added to it

  • 引き出し: 口座から資金を取り出した場合に起こります

  • 送金: 口座が他の口座と資金を交換した場合に起こります

トランザクションが発生したとき、 EconomyTransactionEvent が発火されます。このイベントを使って TransactionResult が取得できます。 TransactionResult は以下を含む発生したトランザクションの情報を持ちます:

  • Account involved

  • Currency involved

  • Amount of currency involved

  • Transaction type

  • Result of the transaction

ResultType JavaDoc のページですべてのあり得るトランザクションの結果を見られます。