Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I create a WorldBorder using PocketMine-MP?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading