From 468c12a868728ef6fac5d89dc0e5656f5501f42d Mon Sep 17 00:00:00 2001 From: ClickedTran <58399779+Clickedtran@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:50:42 +0700 Subject: [PATCH 1/2] Add CoinAPI for libPiggyEconomy --- src/DaPigGuy/libPiggyEconomy/libPiggyEconomy.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 +} From a2ebcbde2f4fdbe427c353560ddfe5ef7aad8d7b Mon Sep 17 00:00:00 2001 From: ClickedTran <58399779+Clickedtran@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:53:25 +0700 Subject: [PATCH 2/2] Add CoinAPI for libPiggyEconomy --- .../providers/CoinAPIProvider.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/DaPigGuy/libPiggyEconomy/providers/CoinAPIProvider.php 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