Skip to content

Commit

Permalink
libPiggyEconomy v2 - xp no longer limits every other currency to ints
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed May 11, 2020
1 parent 7d637ec commit 1866475
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/DaPigGuy/libPiggyEconomy/providers/EconomyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function getMonetaryUnit(): string

abstract function getMoney(Player $player): float;

abstract function giveMoney(Player $player, int $amount): void;
abstract function giveMoney(Player $player, float $amount): void;

abstract function takeMoney(Player $player, int $amount): void;
abstract function takeMoney(Player $player, float $amount): void;

abstract function setMoney(Player $player, int $amount): void;
abstract function setMoney(Player $player, float $amount): void;
}
6 changes: 3 additions & 3 deletions src/DaPigGuy/libPiggyEconomy/providers/EconomySProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public function getMoney(Player $player): float
return $this->economyAPI->myMoney($player);
}

public function giveMoney(Player $player, int $amount): void
public function giveMoney(Player $player, float $amount): void
{
$this->economyAPI->addMoney($player, $amount);
}

public function takeMoney(Player $player, int $amount): void
public function takeMoney(Player $player, float $amount): void
{
$this->economyAPI->reduceMoney($player, $amount);
}

public function setMoney(Player $player, int $amount): void
public function setMoney(Player $player, float $amount): void
{
$this->economyAPI->setMoney($player, $amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public function getMoney(Player $player): float
return $this->currency->getBalance($player->getName()) ?? $this->currency->getStartingAmount();
}

public function giveMoney(Player $player, int $amount): void
public function giveMoney(Player $player, float $amount): void
{
$this->currency->addToBalance($player->getName(), $amount);
}

public function takeMoney(Player $player, int $amount): void
public function takeMoney(Player $player, float $amount): void
{
$this->currency->removeFromBalance($player->getName(), $amount);
}

public function setMoney(Player $player, int $amount): void
public function setMoney(Player $player, float $amount): void
{
$this->currency->setBalance($player->getName(), $amount);
}
Expand Down
19 changes: 12 additions & 7 deletions src/DaPigGuy/libPiggyEconomy/providers/XPProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DaPigGuy\libPiggyEconomy\providers;

use pocketmine\entity\utils\ExperienceUtils;
use pocketmine\Player;

class XPProvider extends EconomyProvider
Expand All @@ -15,21 +16,25 @@ public function getMonetaryUnit(): string

public function getMoney(Player $player): float
{
return (float) $player->getXpLevel();
return $player->getXpLevel() + $player->getXpProgress();
}

public function giveMoney(Player $player, int $amount): void
public function giveMoney(Player $player, float $amount): void
{
$player->addXpLevels($amount, false);
$levels = (int)floor($amount);
$player->addXpLevels($levels);
$player->addXp((int)(ExperienceUtils::getXpToCompleteLevel($player->getXpLevel()) * ($amount - $levels)));
}

public function takeMoney(Player $player, int $amount): void
public function takeMoney(Player $player, float $amount): void
{
$player->subtractXpLevels($amount);
$this->giveMoney($player, -$amount);
}

public function setMoney(Player $player, int $amount): void
public function setMoney(Player $player, float $amount): void
{
$player->setXpLevel($amount);
$levels = (int)floor($amount);
$player->setXpLevel($levels);
$player->setXpProgress($amount - $levels);
}
}
2 changes: 1 addition & 1 deletion virion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: libPiggyEconomy
version: 1.0.1
version: 2.0.0
antigen: DaPigGuy\libPiggyEconomy
api: 3.0.0
author: DaPigGuy

0 comments on commit 1866475

Please sign in to comment.