Skip to content

Instantly share code, notes, and snippets.

@Sleaker
Created May 1, 2015 05:39
Show Gist options
  • Save Sleaker/27521de9ca4b418b0fe9 to your computer and use it in GitHub Desktop.
Save Sleaker/27521de9ca4b418b0fe9 to your computer and use it in GitHub Desktop.
Economy Interface Draft
/**
* Rough draft of economy interface, and questions.
*
* Use case: Plugin (Consumer) wants to allow players to buy and sell items from a chest. Plugin (Provider) offers economy/currency
* to do so. The Consumer will need to allow the player to setup the chest to sell the items. This will require an account linked
* to the chest. This could be a new account the consumer sets up, or the player's wallet provided by the economy implementation, or
* another account that the player owns.
*
* When another player purchases an item from the store the consumer initiates a transfer from the purchaser's wallet, to the
* account that was setup for the chest shop, if successful they get the item.
*
* To be able to offer dynamic account linkage does there need to be a way for a consumer to get a list of accounts that are valid
* for use in the player's current context (world, chunk, position. etc), or do we just provide API for grabbing all accounts owned
* by the player.
*
* Do we add inherent permissions on accounts? Ability to deposit but not withdraw? ability to check balance,
* but not withdraw/deposit, etc, or do we leave that up to the implementation and provide no API for checking these from Consumers.
*
* Currencies: Multiple currency support is easily implemented by simply keeping track of balances per currency, but it also brings up
* that some currencies will only support integer values. Should we limit everything to integer operations for simplicity.
* IE, everything happens in cents, and the Economies should format their numbers manually? or do we force handling currencies as
* BigDecimals.
*
*/
public interface Economy {
/**
* Get's the player's wallet. What they are currently holding.
*/
public Account getWallet(Player player);
// How else are would we do account lookups if we want to support something like banks?
public Account getAccount(/* UUID? String? */ );
public boolean transfer(Account from, Account to, Currency currency, Number amount);
public boolean withdraw(Account from, Currency currency, Number amount);
public boolean deposit(Account to, Currency currency, Number amount);
public NumberFormat getFormatter(Currency currency);
public String format(Currency currency, Number amount);
public List<Currency> getCurrencies();
public Double getExchangeRate(Currency from, Currency to);
}
public interface Account {
public String getId();
public boolean transfer(Account to, Currency currency, Number amount);
public boolean withdraw(Currency currency, Number amount);
public boolean deposit(Currency currency, Number amount);
// Owners?
public ? getOwner()
}
public interface Currency {
public String getName();
public String format(Number amount);
public NumberFormat getFormatter();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment