I'm trying to make a world border by getting player coordinate and stopping them from moving past that coordinate. What should I do? Using Pocketmine 4.0.0
I've tried to find a method to get the coordinates but I don't know what to do.
CodePudding user response:
You can use the PlayerMoveEvent.
use pocketmine\event\player\PlayerMoveEvent;
public function onPlayerMove(PlayerMoveEvent $event) : void{
$player = $event->getPlayer();
$world = $player->getWorld();
$dat = $this->getConfig()->get("border");
if(isset($dat[$world->getDisplayName()])){
$v1 = new Vector3($world->getSpawnLocation()->getX(), 0, $world->getSpawnLocation()->getZ());
$v2 = new Vector3($player->getLocation()->getX(), 0, $player->getLocation()->getZ());
if($v2->distance($v1) >= $dat[$world->getDisplayName()]){
$event->cancel();
}
}
}
This will get the coordinates of the player and set the border from the world spawn.
Then in your configuration file:
border:
# world-name: border-size
world: 1000
You can add as many world's as needed. However, some hacked clients can bypass this method.