Skip to content

Commit

Permalink
fix(LegacyAPI): avoid calling null handlers
Browse files Browse the repository at this point in the history
Closes #117
  • Loading branch information
cooldogedev committed Dec 23, 2023
1 parent 76fd70f commit a89f3fc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cooldogedev/BedrockEconomy/api/type/LegacyAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,31 @@ public function getVersion(): string

public function setPlayerBalance(string $username, int $amount, ?Closure $handler = null): void
{
$handler ??= fn () => null;
BedrockEconomyAPI::CLOSURE()->set(Search::EMPTY, $username, $amount, 0, fn () => $handler(true), fn () => $handler(false));
}

public function getPlayerBalance(string $username, ?Closure $handler = null): void
{
$handler ??= fn () => null;
BedrockEconomyAPI::CLOSURE()->get(Search::EMPTY, $username, fn (int $amount) => $handler($amount), fn () => $handler(null));
}

public function addToPlayerBalance(string $username, int $amount, ?Closure $handler = null): void
{
$handler ??= fn () => null;
BedrockEconomyAPI::CLOSURE()->add(Search::EMPTY, $username, $amount, 0, fn () => $handler(true), fn () => $handler(false));
}

public function subtractFromPlayerBalance(string $username, int $amount, ?Closure $handler = null): void
{
$handler ??= fn () => null;
BedrockEconomyAPI::CLOSURE()->subtract(Search::EMPTY, $username, $amount, 0, fn () => $handler(true), fn () => $handler(false));
}

public function transferFromPlayerBalance(string $source, string $target, int $amount, ?Closure $handler = null): void
{
$handler ??= fn () => null;
BedrockEconomyAPI::CLOSURE()->transfer(
source: [
"xuid" => Search::EMPTY,
Expand Down

0 comments on commit a89f3fc

Please sign in to comment.