@ThreadSafe public interface Transactions extends Registry<Transaction>
This is designed around multiple accounts which are not really accounts, but really a system of synchronizing transactions of a particular type. One account, for example, can be used for economy by one plugin, but that can interfere with another plugin's economy. A new account can be made supporting the same types used in the other plugin without interfering. Additionally, this has the advantage of being able to easily access another plugin's economy data, useful for providing hooks.
Example:
// Economy
private static final Transactions handler = Registered.transactions();
// This must be static! Or you would end up with many different transactions
// to the wrong account
private static final int ECON_ID = handler.newAccount();
// Deposit
handler.deposit(ECON_ID, new Transaction<Player, Player>(int.class, playerFrom, playerTo, 100) {
@Override public void doTransaction(Type type) {
// If check is not required but is a good debugging safeguard
if (type == Type.DEPOSIT) {
receiver().sendMessage(sender().name() + " has sent you $" + amount());
// You may give items here as well
}
}
});
// Remove
handler.withdraw(ECON_ID, new Transaction<Player, Player>(int.class, playerTo, playerTo, 100) {
@Override public void doTransaction(Type type) {
// If check is not required but is a good debugging safeguard
if (type == Type.WITHDRAW) {
sender().sendMessage("You have withdrawn $" + amount());
// You may give items here as well
}
}
});
// Amount
int amount = handler.amount(ECON_ID, playerTo, int.class);
This class also contains global account IDs for economy and exchange [of items].
Modifier and Type | Method and Description |
---|---|
int |
amount(int account,
Object person,
Object type)
Obtains the amount of an item as indicated by the amount field in each transaction
|
void |
deposit(int account,
Transaction transaction)
Performs a transaction from the transaction's sender to the transaction's receiver
|
int |
globalEconomy()
The global economy ID to be used as the transaction ID
|
int |
globalExchange()
The global exchange ID to be used as the transaction ID
|
int |
newAcount()
Creates a new account from the internal account clock
|
boolean |
withdraw(int account,
Transaction transaction)
Withdraws an item from the account
|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
int newAcount()
int globalEconomy()
This is just a recommendation to use for plugins. You do not need to use this.
int globalExchange()
This is just a recommendation to use for plugins. You do not need to use this.
void deposit(int account, Transaction transaction)
account
- the account ID to be usedtransaction
- the transaction to performboolean withdraw(int account, Transaction transaction)
IMPORTANT: The sender is the person withdrawing from the account. The receiver is not taken into
consideration, so that is allowed to be null
.
account
- the account ID to be usedtransaction
- the transaction to performfalse
if the account for the withdrawer does not exist, true
if the transaction completes
successfullyint amount(int account, Object person, Object type)
account
- the account ID to be usedperson
- the object which the transactions were sent to that is checked by this amountingtype
- the types to find the amount of. Also the parameter in
Transaction.item()
type
found the account of person
,
or Integer.MIN_VALUE
if the account for person
does not exist, or the accound ID is not
used for that personCopyright © 2016. All rights reserved.