/** * @param Account $creditor * @param $amount * @param Entity $owner * @param $due * @param $increasePerHour * @param bool $name * @param bool $creation * @param bool $originalAmount * @param bool $lastInterestUpdate */ public function __construct(Account $creditor, $amount, $owner, $due, $increasePerHour, $name = false, $creation = false, $originalAmount = false, $lastInterestUpdate = false) { // setting defaults if (!$creditor->getName() instanceof Service and !$creditor->getEntity() instanceof PlayerEnt) { throw new \InvalidArgumentException("Loan must be provided by a player or a service"); } if ($creation === false) { $creation = time(); } if (!is_string($name)) { $name = sprintf("Loan from {$creditor->getUniqueName()}"); } $oname = $name; for ($i = 2; $owner->getAccount($name) instanceof Account; $i++) { $name = "{$oname} ({$i})"; } if (!is_numeric($originalAmount)) { $originalAmount = $amount; } if (!is_int($lastInterestUpdate)) { $lastInterestUpdate = time(); } // saving fields $this->name = strtolower($name); $this->creditor = $creditor; $this->amount = $amount; $this->owner = $owner; $this->due = $due; $this->increasePerHour = $increasePerHour; $this->creation = $creation; $this->originalAmount = $originalAmount; $this->lastInterestUpdate = $lastInterestUpdate; }
public function execute_(CommandSender $sender, array $args) { if (!isset($args[1])) { return false; } $name = array_shift($args); $amount = array_shift($args); if (!is_numeric($amount)) { return false; } $amount = floatval($amount); $e = false; if (isset($args[0]) and $args[0] === ".e") { $e = true; array_shift($args); } if ($e) { $ent = $this->getPlugin()->getPlayerEnt($name); if (!$ent instanceof PlayerEnt) { return "{$name} is not registered! If you are using a similar name, don't use '.e'."; } } else { $player = $this->getPlugin()->getServer()->getPlayer($name); if (!$player instanceof Player) { return "{$name} is not online! Try adding '.e' if the player is offline."; } $ent = $this->getPlugin()->getPlayerEnt($player->getName(), false); if (!$ent instanceof PlayerEnt) { throw new \RuntimeException("\$ent is not instance of PlayerEnt. Dump of \$ent: " . var_export($ent, true)); } } $acc = $ent->getAccount($this->accName); $service = $this->getPlugin()->getService()->getService(Service::ACCOUNT_OPS); if ($this->add) { if ($service->pay($acc, $amount, implode(" ", $args), true, $failureReason)) { return "\${$amount} has been given to {$ent->getName()}."; } return Account::transactionFailiureIntToString("Cannot add {$this->accHumanName} to target player because {$failureReason}"); } return $acc->pay($service, $amount, implode(" ", $args), false, $failureReason) ? "\${$amount} has been taken from {$ent->getName()}." : "Cannot remove {$this->accHumanName} from target player because " . Account::transactionFailiureIntToString($failureReason); }