diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 34099bd..4a9e5e1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,9 +13,9 @@ jobs: run: mkdir vendor - name: Download Plugin Dependencies run: | - wget -O vendor/BedrockEconomy.phar https://poggit.pmmp.io/r/211584/BedrockEconomy.phar + wget -O vendor/BedrockEconomy.phar https://poggit.pmmp.io/r/230746/BedrockEconomy.phar wget -O vendor/EconomyAPI.phar https://poggit.pmmp.io/r/153507/EconomyAPI.phar - name: Run PHPStan - uses: paroxity/pmmp-phpstan-action@5.1.2 + uses: paroxity/pmmp-phpstan-action@5.12.0 with: phpstan-config: phpstan.neon.dist diff --git a/src/DaPigGuy/libPiggyEconomy/providers/BedrockEconomyProvider.php b/src/DaPigGuy/libPiggyEconomy/providers/BedrockEconomyProvider.php index 7b1a268..fcb057c 100644 --- a/src/DaPigGuy/libPiggyEconomy/providers/BedrockEconomyProvider.php +++ b/src/DaPigGuy/libPiggyEconomy/providers/BedrockEconomyProvider.php @@ -4,52 +4,78 @@ namespace DaPigGuy\libPiggyEconomy\providers; -use cooldogedev\BedrockEconomy\api\legacy\ClosureContext; +use cooldogedev\BedrockEconomy\api\type\ClosureAPI; use cooldogedev\BedrockEconomy\BedrockEconomy; use cooldogedev\BedrockEconomy\api\BedrockEconomyAPI; -use cooldogedev\BedrockEconomy\api\version\LegacyBEAPI; -use cooldogedev\BedrockEconomy\currency\CurrencyManager; +use cooldogedev\BedrockEconomy\currency\Currency; +use cooldogedev\BedrockEconomy\database\cache\GlobalCache; use pocketmine\player\Player; use pocketmine\Server; class BedrockEconomyProvider extends EconomyProvider { - private LegacyBEAPI $api; - private CurrencyManager $currency; + private ClosureAPI $api; + private Currency $currency; public static function checkDependencies(): bool { - return Server::getInstance()->getPluginManager()->getPlugin("BedrockEconomy") !== null; + $plugin = Server::getInstance()->getPluginManager()->getPlugin("BedrockEconomy"); + return $plugin !== null && version_compare($plugin->getDescription()->getVersion(), '4.0', '>='); } public function __construct() { - $this->api = BedrockEconomyAPI::legacy(); - $this->currency = BedrockEconomy::getInstance()->getCurrencyManager(); + $this->api = BedrockEconomyAPI::CLOSURE(); + $this->currency = BedrockEconomy::getInstance()->getCurrency(); } public function getMonetaryUnit(): string { - return $this->currency->getSymbol(); + return $this->currency->symbol; } public function getMoney(Player $player, callable $callback): void { - $this->api->getPlayerBalance($player->getName(), ClosureContext::create(fn(?int $balance) => $callback($balance ?? $this->currency->getDefaultBalance()))); + $entry = GlobalCache::ONLINE()->get($player->getName()); + $callback($entry ? (float)"{$entry->amount}.{$entry->decimals}" : (float)"{$this->currency->defaultAmount}.{$this->currency->defaultDecimals}"); } public function giveMoney(Player $player, float $amount, ?callable $callback = null): void { - $this->api->addToPlayerBalance($player->getName(), (int)$amount, $callback ? ClosureContext::create($callback) : null); + $decimals = (int)(explode('.', strval($amount))[1] ?? 0); + $this->api->add( + $player->getXuid(), + $player->getName(), + (int)$amount, + $decimals, + fn () => $callback ? $callback(true) : null, + fn () => $callback ? $callback(false) : null + ); } public function takeMoney(Player $player, float $amount, ?callable $callback = null): void { - $this->api->subtractFromPlayerBalance($player->getName(), (int)$amount, $callback ? ClosureContext::create($callback) : null); + $decimals = (int)(explode('.', strval($amount))[1] ?? 0); + $this->api->subtract( + $player->getXuid(), + $player->getName(), + (int)$amount, + $decimals, + fn () => $callback ? $callback(true) : null, + fn () => $callback ? $callback(false) : null + ); } public function setMoney(Player $player, float $amount, ?callable $callback = null): void { - $this->api->setPlayerBalance($player->getName(), (int)$amount, $callback ? ClosureContext::create($callback) : null); + $decimals = (int)(explode('.', strval($amount))[1] ?? 0); + $this->api->set( + $player->getXuid(), + $player->getName(), + (int)$amount, + $decimals, + fn () => $callback ? $callback(true) : null, + fn () => $callback ? $callback(false) : null + ); } } diff --git a/virion.yml b/virion.yml index 0ed168a..859082f 100644 --- a/virion.yml +++ b/virion.yml @@ -1,5 +1,5 @@ name: libPiggyEconomy -version: 3.0.2 +version: 3.0.3 antigen: DaPigGuy\libPiggyEconomy api: 5.0.0 author: DaPigGuy \ No newline at end of file