コード例 #1
0
 public function onRun(array $args, Faction $faction)
 {
     if (!isset($args[0])) {
         $args[0] = "check";
     }
     switch ($args[0]) {
         case "on":
         case "yes":
         case "open":
         case "true":
         case "unwhite":
         case "unwhitelist":
             $fee = $this->getMain()->getSetOpenFee();
             $account = $faction->getAccount($fee["account"]);
             if ($account->canPay($fee["amount"])) {
                 return "Your faction doesn't have enough " . $account->getName() . " money to turn off white-list!";
             }
             $account->pay($this->getMain()->getXEconService(), $fee["amount"], "Opening faction for joining");
             $faction->setWhitelisted(false);
             $faction->sendMessage("Your faction is now open for joining.", Faction::CHAT_ANNOUNCEMENT);
             return "";
         case "off":
         case "no":
         case "close":
         case "false":
         case "white":
         case "whitelist":
             $fee = $this->getMain()->getSetNotOpenFee();
             $account = $faction->getAccount($fee["account"]);
             if ($account->canPay($fee["amount"])) {
                 return "Your faction doesn't have enough " . $account->getName() . " money to turn on white-list!";
             }
             $account->pay($this->getMain()->getXEconService(), $fee["amount"], "White-listing faction");
             $faction->setWhitelisted(true);
             $faction->sendMessage("Your faction is now white-listed.", Faction::CHAT_ANNOUNCEMENT);
             return "";
     }
     return $faction->isOpen() ? "Your faction is open for joining." : "Your faction is white-listed.";
 }
コード例 #2
0
 public function onRun(array $args, Faction $faction, Player $player)
 {
     if (!isset($args[0])) {
         $args[0] = "default";
     }
     if (!$faction->hasChunk(Chunk::fromObject($player))) {
         return "Homes must be created in chunks claimed by your faction!";
     }
     $homes = $faction->getHomes();
     if (isset($homes[$args[0]])) {
         $fee = $this->getMain()->getMoveHomeFee();
         $account = $faction->getAccount($fee["account"]);
         if (!$account->canPay($fee["amount"])) {
             return "Your faction doesn't have enough " . $fee["account"] . " money to move a home.";
         }
         $account->pay($this->getMain()->getXEconService(), $fee["amount"], "Moving home");
         $faction->setHome($args[0], $player);
         // a new position will be created instead of the player position
         $faction->sendMessage("Faction {$args['0']} home has been moved to " . $player->getName() . "'s location.", Faction::CHAT_ANNOUNCEMENT);
         return "";
     }
     if (count($homes) + 1 > ($max = $this->getMain()->getMaxHomes())) {
         //whaaaaa??? || only 1 home foreach factions please xD
         return "A faction can only set a maximum of {$max} home(s)!";
         //what???????? || on FactionsBukkit, their is only 1 home.
     }
     $fee = $this->getMain()->getNewHomeFee();
     $account = $faction->getAccount($fee["account"]);
     if (!$account->canPay($fee["amount"])) {
         return "Your faction doesn't have enough " . $fee["account"] . " money to add a new home.";
     }
     $account->pay($this->getMain()->getXEconService(), $fee["amount"], "Adding new home");
     $faction->setHome($args[0], $player);
     $faction->sendMessage("A new home of {$args['0']} has been created at " . $player->getName() . "'s location.", Faction::CHAT_ANNOUNCEMENT);
     return "";
 }
コード例 #3
0
 public function onRun(array $args, Faction $faction)
 {
     if (!isset($args[0])) {
         $name = "default";
     } else {
         $name = array_shift($args);
     }
     $fee = $this->getMain()->getRmHomeFee();
     $account = $faction->getAccount($fee["account"]);
     if (!$account->canPay($fee["amount"])) {
         return "Your faction don't have enough " . $fee["account"] . " money to remove a home.";
     }
     $account->pay($this->getMain()->getXEconService(), $fee["amount"], "Home removal");
     return $faction->rmHome($name) ? "{$name} home has been removed." : "Home \"" . $name . "\" not found.";
 }
コード例 #4
0
 public function onRun(array $args, Faction $faction, Player $player)
 {
     if (!isset($args[0])) {
         return self::WRONG_USE;
     }
     /** @var \xecon\XEcon $xEcon */
     $xEcon = $this->getMain()->getServer()->getPluginManager()->getPlugin("xEcon");
     $ent = $xEcon->getPlayerEnt($player);
     $account = $ent->getAccount(PlayerEnt::ACCOUNT_BANK);
     $amount = (int) array_shift($args);
     if ($account->canPay($amount)) {
         $factionAccount = $faction->getAccount("Bank");
         $account->pay($factionAccount, $amount, "Donation");
     }
     $faction->sendMessage("Received a donation of \${$amount} from " . $player->getName() . "!");
     return "\${$amount} has been deposited into the faction bank from your bank account.";
 }
コード例 #5
0
 public function onRun(array $args, Faction $faction)
 {
     if (!isset($args[0])) {
         return self::WRONG_USE;
     }
     $name = array_shift($args);
     if (preg_replace($this->main->getFactionNamingRule(), "", $name) !== "") {
         return $this->getMain()->getFactionNameErrorMsg();
     } elseif (is_int($this->getMain()->getFList()->getFactionID($name))) {
         return "A faction with name \"{$name}\" already exists!";
     }
     $fee = $this->getMain()->getFactionRenameFee();
     $account = $faction->getAccount($fee["account"]);
     $amount = $account->getAmount() - $fee["amount"];
     if ($amount < 0 - $this->getMain()->getMaxBankOverdraft() and $fee["account"] === "bank" or $amount < 0) {
         return "Your faction doesn't have enough money to rename :( consider taking loans or donating money?";
     }
     $faction->setName($name);
     $account->pay($this->getMain()->getXEconService(), $fee["amount"]);
     $faction->sendMessage("The faction name has been changed to {$args['0']}!");
     return "";
 }
コード例 #6
0
 public function onRun(array $args, Faction $faction, Player $player)
 {
     if (!isset($args)) {
         return self::WRONG_USE;
     }
     $rank = $faction->getMemberRank($player);
     switch ($cmd = array_shift($args)) {
         case "view":
         case "balance":
             $player->sendMessage("Bank balance: \$" . $faction->getAccount(Faction::BANK)->getAmount());
             return "Cash balance: \$" . $faction->getAccount(Faction::CASH)->getAmount();
         case "withdraw":
             if (!$rank->hasPerm(Rank::P_SPEND_MONEY_BANK) or !$rank->hasPerm(Rank::P_DEPOSIT_MONEY_CASH)) {
                 return self::NO_PERM;
             }
             if (!isset($args[0])) {
                 return self::WRONG_USE;
             }
             $amount = array_shift($args);
             $bank = $faction->getAccount(Faction::BANK);
             $cash = $faction->getAccount(Faction::CASH);
             if (!$bank->canPay($amount)) {
                 return "You don't have so much money in your faction bank!";
             }
             $bank->pay($cash, $amount, "Cash withdrawal");
             return "\${$amount} has been withdrawn from your faction bank.";
         case "deposit":
             if (!$rank->hasPerm(Rank::P_SPEND_MONEY_CASH) or !$rank->hasPerm(Rank::P_DEPOSIT_MONEY_BANK)) {
                 return self::NO_PERM;
             }
             if (!isset($args[0])) {
                 return self::WRONG_USE;
             }
             $amount = array_shift($args);
             $bank = $faction->getAccount(Faction::BANK);
             $cash = $faction->getAccount(Faction::CASH);
             if (!$cash->canPay($amount)) {
                 return "Your faction don't have so much cash to deposit!";
             }
             $cash->pay($bank, $amount, "Cash deposit");
             return "\${$amount} of cash has been deposited into your faction bank.";
         case "ff":
             if (!isset($args[1])) {
                 return "Usage: /f money ff <faction> <amount>";
             }
             $other = $this->getMain()->getFList()->getFactionBySimilarName(array_shift($args));
             $amount = (int) array_shift($args);
             if ($amount <= 0) {
                 return "Amount must be larger than zero.";
             }
             $account = $faction->getAccount(Faction::CASH);
             if (!$account->canPay($amount)) {
                 return "Your faction doesn't have enough cash!";
             }
             $otherAccount = $other->getAccount(Faction::CASH);
             $account->pay($otherAccount, $amount, "Transfer using /f money ff");
             $other->sendMessage("\${$amount} cash has been transferred from faction {$faction}.");
             return "\${$amount} cash has been transferred to faction {$other}.";
         case "pf":
             return "Please use \"/f donate\" instead.";
         case "export":
             // TODO
             return "TODO";
     }
     return self::WRONG_USE;
 }