Ejemplo n.º 1
0
 public function execute(CommandSender $sender, $label, array $params)
 {
     if (!$this->plugin->isEnabled()) {
         return false;
     }
     if (!$this->testPermission($sender)) {
         return false;
     }
     if (!$sender instanceof Player) {
         $sender->sendMessage(TextFormat::RED . "Please run this command in-game.");
         return true;
     }
     $player = array_shift($params);
     $amount = array_shift($params);
     if (!is_numeric($amount)) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->getUsage());
         return true;
     }
     if (($p = $this->plugin->getServer()->getPlayer($player)) instanceof Player) {
         $player = $p->getName();
     }
     if (!$this->plugin->accountExists($player)) {
         $sender->sendMessage($this->plugin->getMessage("player-never-connected", [$player], $sender->getName()));
         return true;
     }
     $this->plugin->getServer()->getPluginManager()->callEvent($ev = new PayMoneyEvent($this->plugin, $sender->getName(), $player, $amount));
     $result = EconomyAPI::RET_CANCELLED;
     if (!$ev->isCancelled()) {
         $result = $this->plugin->reduceMoney($sender, $amount);
     }
     if ($result === EconomyAPI::RET_SUCCESS) {
         $this->plugin->addMoney($player, $amount, true);
         $sender->sendMessage($this->plugin->getMessage("pay-success", [$amount, $player], $sender->getName()));
         if ($p instanceof Player) {
             $p->sendMessage($this->plugin->getMessage("money-paid", [$sender->getName(), $amount], $sender->getName()));
         }
     } else {
         $sender->sendMessage($this->plugin->getMessage("pay-failed", [$player, $amount], $sender->getName()));
     }
     return true;
 }
Ejemplo n.º 2
0
 public function onPayEvent(PayMoneyEvent $event)
 {
     $target = strtolower($event->getTarget());
     $player = strtolower($event->getPayer());
     if (isset($this->usuryHosts[$target]["players"][$player])) {
         $condition = $this->usuryHosts[$target]["players"][$player];
         $mustPay = $condition[5];
         $amount = $event->getAmount();
         if ($mustPay <= $amount) {
             $this->queueMessage($player, $this->getMessage("paid-all", [$target, "%2"]));
             $this->queueMessage($target, $this->getMessage("client-paid-all", [$player, "%2"]));
             $this->addItem($player, Item::get($condition[0], $condition[2], $condition[3]));
             $this->getServer()->getScheduler()->cancelTask($condition[6]);
             unset($this->usuryHosts[$target]["players"][$player]);
             return;
         }
         $this->usuryHosts[$target]["players"][$player][5] -= $amount;
         $this->queueMessage($player, $this->getMessage("loan-left", [$this->usuryHosts[$target]["players"][$player][5], $target]));
     }
 }