From 4cad552909e50b565af731d0a49201a2a41cef2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AD=E3=82=89=E3=81=B2=E3=81=8B=E3=81=A0?= Date: Mon, 15 Nov 2021 05:07:37 +0900 Subject: [PATCH] Allow input of relative coordinates to setworldspawn command (#4575) --- src/command/defaults/SetWorldSpawnCommand.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/command/defaults/SetWorldSpawnCommand.php b/src/command/defaults/SetWorldSpawnCommand.php index 1257e388f..96582a349 100644 --- a/src/command/defaults/SetWorldSpawnCommand.php +++ b/src/command/defaults/SetWorldSpawnCommand.php @@ -31,6 +31,7 @@ use pocketmine\math\Vector3; use pocketmine\permission\DefaultPermissionNames; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use pocketmine\world\World; use function count; class SetWorldSpawnCommand extends VanillaCommand{ @@ -60,8 +61,18 @@ class SetWorldSpawnCommand extends VanillaCommand{ return true; } }elseif(count($args) === 3){ - $world = $sender->getServer()->getWorldManager()->getDefaultWorld(); - $pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2])); + if($sender instanceof Player){ + $base = $sender->getPosition(); + $world = $base->getWorld(); + }else{ + $base = new Vector3(0.0, 0.0, 0.0); + $world = $sender->getServer()->getWorldManager()->getDefaultWorld(); + } + $pos = (new Vector3( + $this->getRelativeDouble($base->x, $sender, $args[0]), + $this->getRelativeDouble($base->y, $sender, $args[1], World::Y_MIN, World::Y_MAX), + $this->getRelativeDouble($base->z, $sender, $args[2]), + ))->floor(); }else{ throw new InvalidCommandSyntaxException(); }