public function onRun(array $args, Faction $faction, Player $player)
 {
     $chunk = Chunk::fromObject($player);
     $owner = $this->getMain()->getFList()->getFaction($chunk);
     if (!$owner instanceof Faction) {
         return "You cannot siege a wilderness chunk. Consider using \"/f claim\".";
     }
     $state = $this->getMain()->getFList()->getFactionsState($faction, $owner);
     if ($state !== State::REL_ENEMY) {
         return "Your faction has to declare enemy to faction {$owner} to siege their chunks.";
     }
     $power = $owner->powerClaimable() - count($owner->getChunks());
     if ($power >= 0) {
         return "Faction {$owner} doesn't have power overdraft. You can only siege chunks from factions with overdraft power.";
     }
     $power = ($faction->getPower() - $this->getMain()->getSiegeReputationLoss()) / $this->getMain()->getClaimSingleChunkPower();
     if ($power < 0) {
         return "Your faction doesn't have enough power to siege a chunk.";
     }
     $x = self::mod($player->getX(), 16);
     $z = self::mod($player->getZ(), 16);
     if ((new Vector2($x, $z))->distance(8, 8) >= ($radius = $this->getMain()->getSiegeRadius())) {
         return "You must be less than {$radius} blocks from the chunk center to siege the chunk.";
     }
     $owner->forceUnclaim($chunk);
     $faction->claim($chunk, $player);
     $faction->loseReputation($this->getMain()->getSiegeReputationLoss());
     $owner->sendMessage("You have a chunk sieged by faction {$faction}!", Faction::CHAT_ANNOUNCEMENT);
     return "Chunk sieged from faction {$owner}!";
 }
 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)
 {
     if (!$faction->canClaimMore()) {
         return "[PF] Your faction does not have power to\n[PF] claim any more chunks!";
     }
     if ($this->getMain()->getFList()->getFaction(Chunk::fromObject($player)) instanceof Faction) {
         return "[PF] This chunk has already been claimed!";
     }
     $success = $faction->claim(Chunk::fromObject($player), $player);
     return $success ? "[PF] You have claimed this 16x16 chunk!" : "[PF] Your faction does not have enough\n[PF] money to claim this chunk!";
 }
 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 "";
 }
 /**
  * @param EntityDamageByEntityEvent $event
  * @priority HIGH
  * @ignoreCancelled true
  */
 public function onFight(EntityDamageByEntityEvent $event)
 {
     if (!$this->isFactionWorld($event->getEntity()->getLevel()->getName())) {
         return;
     }
     $victim = $event->getEntity();
     $attacker = $event->getDamager();
     if (!$attacker instanceof Player or !$victim instanceof Player) {
         return;
     }
     /** @noinspection PhpUnusedLocalVariableInspection */
     $at = $this->getFList()->getFaction(Chunk::fromObject($victim));
     $attackf = $this->getFList()->getFaction($attacker);
     $victimf = $this->getFList()->getFaction($victim);
     /** @noinspection PhpUnusedLocalVariableInspection */
     $state = $this->getFList()->getFactionsState($attackf, $victimf);
     // TODO
 }
 public function hasChunk(Chunk $chunk)
 {
     foreach ($this->chunks as $cchunk) {
         if ($chunk->equals($cchunk)) {
             return true;
         }
     }
     return false;
 }