示例#1
0
 /**
  * @param Player|string $player
  * @param float $money
  * @param bool $force
  * @param string $issuer
  *
  * @return int
  */
 public function setMoney($player, $amount, $force = false, $issuer = "external")
 {
     if ($amount < 0 or !is_numeric($amount)) {
         return self::RET_INVALID;
     }
     if (($money = $this->provider->getMoney($player)) !== false) {
         $money = min($this->config->get("max-money"), $amount);
         $ev = new SetMoneyEvent($this, $player, $money, $issuer);
         $this->getServer()->getPluginManager()->callEvent($ev);
         if ($force === false and $ev->isCancelled()) {
             return self::RET_CANCELLED;
         }
         $this->provider->setMoney($player, $amount);
         $this->getServer()->getPluginManager()->callEvent(new MoneyChangedEvent($this, $player, $amount, $issuer));
         return self::RET_SUCCESS;
     } else {
         return self::RET_NOT_FOUND;
     }
 }
示例#2
0
 /**
  * @param string|Player 	$player
  * @param float 			$amount
  * @param bool				$force
  * @param string			$issuer
  *
  * @return int
  */
 public function reduceMoney($player, $amount, bool $force = false, $issuer = "none") : int
 {
     if ($amount < 0) {
         return self::RET_INVALID;
     }
     if ($player instanceof Player) {
         $player = $player->getName();
     }
     $player = strtolower($player);
     if (($money = $this->provider->getMoney($player)) !== false) {
         $amount = round($amount, 2);
         if ($money - $amount < 0) {
             return self::RET_INVALID;
         }
         $this->getServer()->getPluginManager()->callEvent($ev = new ReduceMoneyEvent($this, $player, $amount, $issuer));
         if (!$ev->isCancelled() or $force === true) {
             $this->provider->reduceMoney($player, $amount);
             $this->getServer()->getPluginManager()->callEvent(new MoneyChangedEvent($this, $player, $money - $amount, $issuer));
             return self::RET_SUCCESS;
         }
         return self::RET_CANCELLED;
     }
     return self::RET_NO_ACCOUNT;
 }