Skip to content

Commit

Permalink
Make use of cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Joestarfish committed Mar 8, 2024
1 parent 24641a1 commit 59f7186
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use cooldogedev\BedrockEconomy\BedrockEconomy;
use cooldogedev\BedrockEconomy\api\BedrockEconomyAPI;
use cooldogedev\BedrockEconomy\currency\Currency;
use cooldogedev\BedrockEconomy\database\cache\GlobalCache;
use pocketmine\player\Player;
use pocketmine\Server;

Expand Down Expand Up @@ -35,12 +36,8 @@ public function getMonetaryUnit(): string

public function getMoney(Player $player, callable $callback): void
{
$this->api->get(
$player->getXuid(),
$player->getName(),
fn (array $result) => $callback((float)"$result[amount].$result[decimals]"),
fn () => $callback((float)"{$this->currency->defaultAmount}.{$this->currency->defaultDecimals}")
);
$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
Expand Down

0 comments on commit 59f7186

Please sign in to comment.