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; }
/** * @param string $name * @param string $founder name of the faction founder * @param Rank[] $ranks * @param int $defaultRankIndex the default rank's key in $ranks * @param int $allyRankIndex * @param int $truceRankIndex * @param int $stdRankIndex * @param Main $main * @param Position|Position[] $home the home position of the faction * @param string $motto * @param bool $whitelist * @param int|bool $id * @param int $reputation * @return Faction */ public static function newInstance($name, $founder, array $ranks, $defaultRankIndex, $allyRankIndex, $truceRankIndex, $stdRankIndex, Main $main, $home, $motto = "", $whitelist = true, $id = false, $reputation = 0) { if (!is_int($id)) { $id = self::nextID($main); } $data = ["name" => $name, "motto" => $motto, "id" => $id, "founder" => strtolower($founder), "ranks" => $ranks, "default-rank" => $defaultRankIndex, "ally-rank" => $allyRankIndex, "truce-rank" => $truceRankIndex, "std-rank" => $stdRankIndex, "members" => [], "last-active" => time(), "chunks" => [], "homes" => (array) $home, "base-chunk" => Chunk::fromObject($home), "whitelist" => $whitelist, "reputation" => $reputation]; $faction = new Faction($data, $main); $main->getFList()->add($faction); return $faction; }
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 }