public function onRun(array $args, Faction $faction, Player $player)
 {
     $chunk = Chunk::fromObject($player);
     if (!$faction->getMemberRank($player)->hasPerm(Rank::P_UNCLAIM_CENTER) and $faction->isCentreLocation($player)) {
         return self::NO_PERM;
     }
     return ($result = $faction->unclaim($chunk)) === true ? "The chunk you are standing in has been unclaimed." : $result;
 }
 public function onRun(array $args, Faction $faction, Player $player)
 {
     $reason = implode(" ", $args);
     $members = $faction->getMembers(true);
     unset($members[strtolower($player->getName())]);
     $faction->setMembers($members);
     $faction->sendMessage($player->getName() . " quitted the faction.", Faction::CHAT_ANNOUNCEMENT);
     if (strlen($reason) > 0) {
         $faction->sendMessage("Reason: {$reason}");
     }
     return "[PF] You have successfully quitted {$faction}.";
 }
 public function checkPermission(Faction $faction, Player $player)
 {
     $rank = $faction->getMemberRank($player);
     $perm = $rank->hasPerm(Rank::P_CLAIM);
     $fee = $this->getMain()->getChunkClaimFee();
     if ($fee["amount"] === 0) {
         return $perm;
     }
     if ($fee["account"] === "bank") {
         return $perm and $rank->hasPerm(Rank::P_SPEND_MONEY_BANK);
     }
     return $perm and $rank->hasPerm(Rank::P_SPEND_MONEY_CASH);
 }
 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.";
 }
 public function onRun(array $args, Faction $faction, Player $player)
 {
     if (!isset($args[0])) {
         return self::WRONG_USE;
     }
     if ($faction->hasMember($name = strtolower(array_shift($args)))) {
         if ($name === $faction->getFounder()) {
             return "You can't kick the founder!";
         }
         $faction->kick($name);
         $faction->sendMessage("{$name} has been kicked by " . $player->getName() . ". Reason: " . implode(" ", $args));
         if (($p = $this->getMain()->getServer()->getPlayerExact($name)) instanceof Player) {
             $p->sendMessage("You have been kicked from the faction. Reason: " . implode(" ", $args));
         }
     }
     return self::NO_PLAYER;
 }
 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.";
 }
 public function onRun(array $args, Faction $faction, Player $player)
 {
     // TODO find the correct named home
     if (isset($args[0])) {
         $home = $faction->getHome($args[0]);
         if ($home instanceof Position) {
             $player->teleport($home);
             return "You have been teleported to {$args['0']}.";
         }
         return "There is no such home named \"{$args['0']}\"!";
     }
     $home = $faction->getHome();
     if ($home instanceof Position) {
         $player->teleport($home);
         return "You have been teleported to your faction home.";
     }
     return "Your faction doesn't seem to have a home.";
 }
 public function onRun(array $args, Player $player)
 {
     if (!isset($args[0])) {
         return self::WRONG_USE;
     }
     $name = $args[0];
     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!";
     }
     Faction::newInstance($name, $player->getName(), $this->getMain()->getDefaultRanks(), $this->getMain()->getDefaultRank(), $this->getMain()->getDefaultAllyRank(), $this->getMain()->getDefaultTruceRank(), $this->getMain()->getDefaultStdRank(), $this->main);
     $this->main->getServer()->broadcast("[PF] A new faction called {$name} has been created!", Server::BROADCAST_CHANNEL_USERS);
     return "";
 }
 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 "";
 }
 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.";
 }
 public function checkPermission(Faction $faction, Player $player)
 {
     return $faction->getMemberRank($player->getName())->hasPerm(Rank::P_INVITE);
 }
 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;
 }
 public function onRun(array $args, Faction $faction, Player $player)
 {
     return "Homes of {$faction}: " . implode(", ", array_keys($faction->getHomes()));
 }
 public function onRejected()
 {
     /** @var Faction $to */
     $to = $this->getTo();
     $this->from->sendMessage("The request to be " . $this->getState() . " factions with " . $to->getDisplayName() . " has been rejected!");
 }
 public function onRun(array $args, Faction $faction, Player $player)
 {
     $faction->unclaimAll();
     $faction->sendMessage("All chunks have been unclaimed!");
     return "";
 }
 public function onRun(array $args, Faction $faction, Player $player)
 {
     $faction->sendMessage($player->getName() . " disbanded this faction! Reason given: " . implode(" ", $args), Faction::CHAT_ALL);
     $this->main->getFList()->disband($faction);
 }
 public function checkPermission(Faction $faction, Player $player)
 {
     return $faction->getMemberRank($player)->hasPerm(Rank::P_SIEGE);
 }
示例#18
0
 public function onRun(array $args, Faction $faction, Player $player)
 {
     switch ($sub = strtolower(array_shift($args))) {
         case "types":
             return "Types of loans: " . implode(", ", array_keys($this->getMain()->getBankLoanTypesRaw()));
         case "view":
             return "Operation not supported";
             /*$data = [
             			"type" => ["type"],
             			"amount" => ["amount"],
             			"interest" => ["interest"],
             			"creation" => ["borrowed at"],
             			"due" => ["due at"],
             		];
             		foreach($faction->getLoans() as $liability){
             			$data["type"][] = strstr($liability->getName(), " ", true);
             			$data["amount"] = "\$".$liability->getAmount();
             			$data["interest"][] = "\$".($liability->getAmount() - $liability->getOriginalAmount());
             			$data["creation"][] = date("M j, y H:i", $liability->getCreationTime());
             			$data["due"][] = date("M j, y H:i", $liability->getDue());
             		}
             		$out = "Your faction's loans: (current datetime is ".date("M j, y H:i:s").")\n";
             		foreach($data as $key => $d){
             			$max = max(array_map("strlen", $d));
             			foreach($d as $k => $v){
             				$data[$key][$k] .= str_repeat(" ", $max - strlen($v));
             			}
             		}
             		for($i = 0; $i < count($data["type"]); $i++){
             			$dat = [
             				$data["type"][$i],
             				$data["amount"][$i],
             				$data["interest"][$i],
             				$data["creation"][$i],
             				$data["due"]];
             			$out .= implode(" | ", $dat);
             		}
             		return $out;*/
         /*$data = [
         			"type" => ["type"],
         			"amount" => ["amount"],
         			"interest" => ["interest"],
         			"creation" => ["borrowed at"],
         			"due" => ["due at"],
         		];
         		foreach($faction->getLoans() as $liability){
         			$data["type"][] = strstr($liability->getName(), " ", true);
         			$data["amount"] = "\$".$liability->getAmount();
         			$data["interest"][] = "\$".($liability->getAmount() - $liability->getOriginalAmount());
         			$data["creation"][] = date("M j, y H:i", $liability->getCreationTime());
         			$data["due"][] = date("M j, y H:i", $liability->getDue());
         		}
         		$out = "Your faction's loans: (current datetime is ".date("M j, y H:i:s").")\n";
         		foreach($data as $key => $d){
         			$max = max(array_map("strlen", $d));
         			foreach($d as $k => $v){
         				$data[$key][$k] .= str_repeat(" ", $max - strlen($v));
         			}
         		}
         		for($i = 0; $i < count($data["type"]); $i++){
         			$dat = [
         				$data["type"][$i],
         				$data["amount"][$i],
         				$data["interest"][$i],
         				$data["creation"][$i],
         				$data["due"]];
         			$out .= implode(" | ", $dat);
         		}
         		return $out;*/
         case "take":
             if (!isset($args[0])) {
                 return "Usage: /f loan take <type>\n[PF] <type> is listed at /f loan types";
             }
             $type = array_shift($args);
             return $faction->addLoan_faction($type);
         case "repay":
         case "return":
             return "Operation not supported";
             /*
             				if(!isset($args[0]) or !is_numeric($args[0])){
             					return "Usage: /loan return <amount>"; // TODO filters
             				}
             				$amount = array_shift($args);
             				$account = $faction->getAccount(Faction::CASH);
             				if(!$account->canPay($amount)){
             					return "Loans are repaid via cash. Please withdraw enough money for your faction's cash account.";
             				}
             				$picked = null;
             				foreach($faction->getLoans() as $l){
             					// TODO allow customization here via arg 3
             					if($l instanceof \xecon\account\Loan){
             						if(!($picked instanceof \xecon\account\Loan)){
             							$picked = $l;
             							continue;
             						}
             						if($picked->getDue() < $l->getDue()){
             							$picked = $l;
             							continue;
             						}
             						if($picked->getDue() === $l->getDue()){
             							if($l->getHourlyIncrease() > $picked->getHourlyIncrease()){
             								$picked = $l;
             								continue;
             							}
             							elseif($l->getAmount() < $picked->getAmount()){
             								$picked = $l;
             							}
             						}
             					}
             				}
             				if($picked === null){
             					return "You have no loans to repay!";
             				}
             				$account->pay($picked, $amount, "Repaid a loan");*/
     }
     return self::WRONG_USE;
 }