Developer documentation - SoKnight/PEconomy GitHub Wiki
Introduction
Before working with PEconomy you need add this dependency to your project!
The main package of the plugin is ru.soknight.peconomy, please, import all next types from that.
All API methods are located in the PEconomyAPI
interface.
Getting API instance
Firstly you need to get the API instance using one of two ways:
- Call static
#getAPI()
fromPEconomy
- Call static
#get()
fromPEconomyAPI
(a proxy for the method #1)
Simple example:
import ru.soknight.peconomy.api.PEconomyAPI;
PEconomyAPI api = PEconomyAPI.get();
Usage of API methods
All API methods are described with Javadoc already, you just should import sources
JAR too.
You can example usage of some methods below.
import ru.soknight.peconomy.api.PEconomyAPI;
import ru.soknight.peconomy.database.model.WalletModel;
// getting the API instance
PEconomyAPI api = PEconomyAPI.get();
// getting SoKnight's wallet (nullable)
// this method will lock current thread to run SQL statement!
WalletModel wallet = api.getWallet("SoKnight");
if(wallet == null) {
System.err.println("SoKnight has no wallet!");
return;
}
// adding 124,56 dollars to SoKnight's wallet
float amount = 124.56F;
wallet.addAmount("dollars", amount);
// now we must save changed wallet instance to database
// this method will lock current thread too!
api.updateWallet(wallet);
float balance = wallet.getAmount("dollars");
System.out.printf("Added %s to SoKnight's wallet, current balance is %s!", amount, balance);
Custom banking implementation
PEconomy will not support Vault banking system in the future and that isn't supported now. But you can register your own banking implementation for Vault via PEconomy API!
Example banking implementation:
import net.milkbowl.vault.economy.EconomyResponse;
import ru.soknight.peconomy.api.BankingProvider;
import ru.soknight.peconomy.api.PEconomyAPI;
// don't forget about implementing an interface
public class MyBankingSystem implements BankingProvider {
// register our banking implementation via PEconomy API
public void register() {
PEconomyAPI.get().registerBankingProvider(this);
}
@Override
public EconomyResponse createBank(String name, String player) {
// and now you need implement all methods from the BankingProvider interface
// TODO your code
}
}