Skip to content

Commit

Permalink
Implement PlayerPortalTeleportEvent::$block_position (position of the…
Browse files Browse the repository at this point in the history
… portal block)
  • Loading branch information
Muqsit committed Mar 25, 2024
1 parent 1df0aa0 commit 169f7d2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: DimensionPortals
main: muqsit\dimensionportals\Loader
api: 5.10.0
version: 0.2.1
version: 0.2.2
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
use pocketmine\world\Position;

class PlayerPortalTeleportEvent extends DimensionPortalsEvent implements Cancellable{
use CancellableTrait;

public function __construct(
readonly public Player $player,
readonly public PortalExoBlock $block,
readonly public Position $block_position,
public Location $target
){}

Expand Down
4 changes: 2 additions & 2 deletions src/muqsit/dimensionportals/player/PlayerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(Player $player, Logger $logger){
public function onEnterPortal(PortalExoBlock $block, Position $position) : void{
($ev = new PlayerEnterPortalEvent($this->player, $block, $position, $this->player->isCreative() ? 0 : $block->teleportation_duration))->call();
if(!$ev->isCancelled()){
$this->in_portal = new PlayerPortalInfo($block, $ev->teleport_duration);
$this->in_portal = new PlayerPortalInfo($block, $position, $ev->teleport_duration);
PlayerManager::scheduleTicking($this->player);
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ private function teleport() : void{
$to = $this->in_portal->block->getTargetWorldInstance();
$world = (WorldManager::get($this->player->getWorld()) === $to ? WorldManager::getOverworld() : $to)->world;
$target = Location::fromObject($world->getSpawnLocation(), $world, 0.0, 0.0);
($ev = new PlayerPortalTeleportEvent($this->player, $this->in_portal->block, $target))->call();
($ev = new PlayerPortalTeleportEvent($this->player, $this->in_portal->block, $this->in_portal->block_position, $target))->call();
if(!$ev->isCancelled()){
$this->player->teleport($ev->target);
}
Expand Down
2 changes: 2 additions & 0 deletions src/muqsit/dimensionportals/player/PlayerPortalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace muqsit\dimensionportals\player;

use muqsit\dimensionportals\exoblock\PortalExoBlock;
use pocketmine\world\Position;

final class PlayerPortalInfo{

private int $duration = 0;

public function __construct(
readonly public PortalExoBlock $block,
readonly public Position $block_position,
readonly public int $max_duration
){}

Expand Down

0 comments on commit 169f7d2

Please sign in to comment.