Skip to content

Commit

Permalink
Better fix for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris-Driv committed Jul 25, 2017
1 parent 7695a27 commit 0888d31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/factions/engine/MainEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,9 @@ public function onChunksChangeInner($event)
*/
public function teleportToHomeOnRespawn(PlayerRespawnEvent $event) {
$player = Members::get($event->getPlayer());
if($player->hasFaction()) {
if($player->getFaction()->isValidHome($player->getFaction()->getHome())) {
$event->setRespawnPosition($player->getFaction()->getHome());
$player->sendMessage(Text::parse("<b>Teleported to faction home"));
}
if($player->hasFaction() && $player->getFaction()->hasHome()) {
$event->setRespawnPosition($player->getFaction()->getHome());
$player->sendMessage(Text::parse("<b>Teleported to faction home"));
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/factions/entity/Faction.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,13 @@ public function verifyHome()
$this->sendMessage(Localizer::translatable("home-out-of-bounds"));
}

public function isValidHome($home): bool
public function hasHome(): bool {
$this->verifyHome();
return $this->home instanceof Position;
}

public function isValidHome(Position $home): bool
{
if ($home === null) return false;
if (!$home instanceof Position) return false;
if (!Gameplay::get("home.must-be-in-claimed-territories", true)) return true;
if (Plots::getFactionAt($home) === $this) return true;
return false;
Expand Down

0 comments on commit 0888d31

Please sign in to comment.