diff --git a/src/DaPigGuy/libPiggyEconomy/libPiggyEconomy.php b/src/DaPigGuy/libPiggyEconomy/libPiggyEconomy.php index b51b63f..4e80024 100644 --- a/src/DaPigGuy/libPiggyEconomy/libPiggyEconomy.php +++ b/src/DaPigGuy/libPiggyEconomy/libPiggyEconomy.php @@ -10,6 +10,7 @@ use DaPigGuy\libPiggyEconomy\providers\EconomyProvider; use DaPigGuy\libPiggyEconomy\providers\EconomySProvider; use DaPigGuy\libPiggyEconomy\providers\XPProvider; +use DaPigGuy\libPiggyEconomy\providers\CoinAPIProvider; class libPiggyEconomy { @@ -29,6 +30,7 @@ public static function init(): void self::registerProvider(["economys", "economyapi"], EconomySProvider::class); self::registerProvider(["bedrockeconomy"], BedrockEconomyProvider::class); self::registerProvider(["xp", "exp", "experience"], XPProvider::class); + self::registerProvider(["coinapi", "coin"], CoinAPIProvider::class); } } @@ -58,4 +60,4 @@ public static function getProvider(array $providerInformation): EconomyProvider } return new $provider($providerInformation); } -} \ No newline at end of file +} diff --git a/src/DaPigGuy/libPiggyEconomy/providers/CoinAPIProvider.php b/src/DaPigGuy/libPiggyEconomy/providers/CoinAPIProvider.php new file mode 100644 index 0000000..b731e4d --- /dev/null +++ b/src/DaPigGuy/libPiggyEconomy/providers/CoinAPIProvider.php @@ -0,0 +1,52 @@ +getPluginManager()->getPlugin("CoinAPI") !== null; + } + + public function __construct() + { + $this->coinAPI = CoinAPI::getInstance(); + } + + public function getMonetaryUnit(): string + { + return $this->coinAPI->getMonetaryUnit(); + } + + public function getMoney(Player $player, callable $callback): void + { + $callback($this->coinAPI->myCoin($player) ?: 0); + } + + public function giveMoney(Player $player, float $amount, ?callable $callback = null): void + { + $ret = $this->coinAPI->addCoin($player, $amount); + if ($callback) $callback($ret === CoinAPI::RET_SUCCESS); + } + + public function takeMoney(Player $player, float $amount, ?callable $callback = null): void + { + $ret = $this->coinAPI->reduceCoin($player, $amount); + if ($callback) $callback($ret === CoinAPI::RET_SUCCESS); + } + + public function setMoney(Player $player, float $amount, ?callable $callback = null): void + { + $ret = $this->coinAPI->setCoin($player, $amount); + if ($callback) $callback($ret === CoinAPI::RET_SUCCESS); + } +} \ No newline at end of file