I have a small server for me and a couple of friends. We messed up spawn completely, and are now having quite a difficult job getting away from it. I'm planning on writing a plugin that teleports a player to a random set of safe coordinates when they respawn (assuming their spawn point != 0,0 i.e. spawn). What would be the mos efficient (for speed and code readablility) way to do this? For now i just wait for PlayerRespawnEvent, check the coords, and if they are not 0,0 run the following: Code: if ($this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY(), $this->getSpawn()->getZ()))->getId() == Block::AIR && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() + 1, $this->getSpawn()->getZ()))->getId() == Block::AIR && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::AIR && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::LAVA && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::STILL_LAVA && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::FIRE) { echo("safe"); $pos = $this->getSpawn(); } else { echo("not safe"); $this->setSpawn(new Vector3(rand(-127, 127), rand(10, 127), rand(-127, 127))); while (!($this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY(), $this->getSpawn()->getZ()))->getId() == Block::AIR && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() + 1, $this->getSpawn()->getZ()))->getId() == Block::AIR && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::AIR && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::LAVA && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::STILL_LAVA && $this->level->getBlock(new Vector3($this->getSpawn()->getX(), $this->getSpawn()->getY() - 1, $this->getSpawn()->getZ()))->getId() != Block::FIRE)) { echo("try"); $this->setSpawn(new Vector3(rand(-127, 127), rand(10, 127), rand(-127, 127))); } $pos = $this->getSpawn(); } and teleport them to $pos. Is there a better way to do this?
This thread is in the wrong place. It should be in "Plugin Development". As for your problem, I'm a little confused. Can you not get it to work at all? Or does it work, but you just want it to be faster?
Code: /setworldspawn Reference: https://github.com/PocketMine/Pocke...pocketmine/command/defaults/SetWorldSpawn.php That's one hell of a 'if' statement. What do you mean 'messed up'?
Maybe he wants this: Write Code: $this->radius = 100; in onEnable() function And then make example : Code: public function randomTeleport(PlayerMoveEvent $e) { $entity = $e->getPlayer(); $v = new Vector3($entity->getLevel()->getSpawnLocation()->getX(), $entity->getPosition()->getY(), $entity->getLevel()->getSpawnLocation()->getZ()); $rand = mt_rand(1, 3); switch($rand){ case 1: $pos = 0, 0, 0; break; case 2: $pos = 50, 50, 50; break; case 3: $pos = 100, 100, 100; break; } if(floor($entity->distance($v)) >= $this->radius) { $e->setCancelled(); $entity->teleport(new Vector3($pos)); $entity->sendMessage("§eRandom teleport :)"); } }