From 38d905fcfbae84b3c49f2df3831182cc7a66b2a6 Mon Sep 17 00:00:00 2001 From: Diduhless Date: Sat, 2 Feb 2019 16:56:55 +0100 Subject: [PATCH] Fix 'teleport_members_to_leader' not working correctly --- plugin.yml | 2 +- src/Diduhless/Parties/PartiesListener.php | 33 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plugin.yml b/plugin.yml index 8e233f6..02b2b3a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -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] \ No newline at end of file diff --git a/src/Diduhless/Parties/PartiesListener.php b/src/Diduhless/Parties/PartiesListener.php index a1df559..e9b93ba 100644 --- a/src/Diduhless/Parties/PartiesListener.php +++ b/src/Diduhless/Parties/PartiesListener.php @@ -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; @@ -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()); + } } } }