Skip to content

Commit

Permalink
Fix 'teleport_members_to_leader' not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
didacdelolmo committed Feb 2, 2019
1 parent ce164db commit 38d905f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: Parties
author: Didah
description: Parties plugin for PocketMine-MP
website: twitter.com/Diduhless
version: "1.0.1"
version: "1.0.2"
api: [3.0.0]
33 changes: 30 additions & 3 deletions src/Diduhless/Parties/PartiesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\Event;
use pocketmine\event\Listener;
use pocketmine\Player;

Expand All @@ -30,17 +32,42 @@ public function __construct(Parties $plugin) {
*/
public function onLevelChange(EntityLevelChangeEvent $event): void {
$player = $event->getEntity();
if(!$this->plugin->getConfig()->get("teleport_members_to_leader") or !$player instanceof Player) {
if($player instanceof Player) {
$this->onLeaderTeleport($this->plugin->getSessionManager()->getSession($player), $event);
}
}

/**
* @param EntityTeleportEvent $event
*/
public function onTeleport(EntityTeleportEvent $event): void {
$player = $event->getEntity();
if($player instanceof Player) {
$this->onLeaderTeleport($this->plugin->getSessionManager()->getSession($player), $event);
}
}

/**
* @param Session $session
* @param Event $event
*/
public function onLeaderTeleport(Session $session, Event $event): void {
if(!$this->plugin->getConfig()->get("teleport_members_to_leader")) {
return;
}
$session = $this->plugin->getSessionManager()->getSession($player);
if(!$session->hasParty() or !$session->isLeader()) {
return;
}
/** @var Session $member */
foreach($session->getParty()->getMembers() as $member) {
if(!$member->isLeader()) {
$member->getOwner()->teleport($session->getOwner()->asVector3());
$owner = $member->getOwner();
if($event instanceof EntityLevelChangeEvent) {
$owner->teleport($event->getTarget()->getSafeSpawn());
}
if($event instanceof EntityTeleportEvent) {
$owner->teleport($event->getTo());
}
}
}
}
Expand Down

0 comments on commit 38d905f

Please sign in to comment.