-
Notifications
You must be signed in to change notification settings - Fork 0
The basics: Hook into PocketVault
Andre | xZeroMCPE edited this page Sep 28, 2020
·
1 revision
Let's first retrieve an instance of PocketVault
$vault = PocketVault::getInstance();
We can make that better by instead doing something like this:
public function getPocketVault() : PocketVault {
return PocketVault::getInstance()
}
You can place the above method anywhere you'd like, I recommend you place it on your plugin main class.
Checking if an Economy provider exists:
if($this->getPocketVault()->getProviderManager()->hasProvider(ProviderName::ECONOMY)) {
$this->getLogger()->info("Yay! there's an economy provider!"):
// You can now access methods available in the EconomyProvider class
// For example, getting a player balance?
$money = $vault->getProviderManager()->getProvider(ProviderName::ECONOMY)->getBalance($player);
$player->sendMessage("Your available balance is $money");
} else {
$this->getLogger()->error("Ouch man! Does not have an economy provider");
}
The ProviderName
is included in the PocketVault
namespace, it's best to import the PocketVault.phar
so you can get hints in your IDE. i.e; PHPStorm
For a full list of methods available, lurk around the provider's source code :)
Now head over to the next page to see how you can get started creating your own custom Economy provider!
Created by xZeroMCPE