I want to protect every block in a 12-metre radius from a team spawn point. I currently have the following code: PHP: public function onBlockBreak(BlockBreakEvent $event){ $player = $event->getPlayer(); $mapa = $player->getLevel()->getFolderName(); if(in_array($mapa,$this->arena)){ $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML); $level = $this->getServer()->getLevelByName($mapa); if($this->checkTeam($player) == "blue"){ $team = "blue"; $thespawn = $config->get($mapa . "SpawnBLUE"); $x = $event->getBlock()->getX(); $z = $event->getBlock()->getZ(); if (($x<$thespawn[0]+12) || ($x<$thespawn[0]-12) || ($z<$thespawn[2]+12) || ($z<$thespawn[2]-12)){ $event->setCancelled(true); } }elseif($this->checkTeam($player) == "red"){ $team = "red"; $thespawn = $config->get($mapa . "SpawnRED"); $x = $event->getBlock()->getX(); $z = $event->getBlock()->getZ(); if (($x<$thespawn[0]+12) || ($x<$thespawn[0]-12) || ($z<$thespawn[2]+12) || ($z<$thespawn[2]-12)){ $event->setCancelled(true); } } } } public function onBlockPlace(BlockPlaceEvent $event){ $player = $event->getPlayer(); $namemap = $player->getLevel()->getFolderName(); if(in_array($namemap,$this->arena)){ $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML); $level = $this->getServer()->getLevelByName($namemap); if($this->checkTeam($player) == "blue"){ $team = "blue"; $thespawn = $config->get($namemap . "SpawnBLUE"); $x = $event->getBlock()->getX(); $z = $event->getBlock()->getZ(); if (($x<$thespawn[0]+12) || ($x<$thespawn[0]-12) || ($z<$thespawn[2]+12) || ($z<$thespawn[2]-12)){ $event->setCancelled(true); } }elseif($this->checkTeam($player) == "red"){ $team = "red"; $thespawn = $config->get($namemap . "SpawnRED"); $x = $event->getBlock()->getX(); $z = $event->getBlock()->getZ(); if (($x<$thespawn[0]+12) || ($x<$thespawn[0]-12) || ($z<$thespawn[2]+12) || ($z<$thespawn[2]-12)){ $event->setCancelled(true); } } } } I'm still confused about the math involved. Can anybody help me out?
If you want to cancel it within a radius, you're better off using distance() or distanceSquared() PHP: if($event->getBlock()->distance($position) <= 12) { $event->setCancelled();}
Working fine now that I use this code: PHP: $spawn = new Position($thespawn[0],$thespawn[1],$thespawn[2],$level);if($event->getBlock()->distance($spawn) <= 12) { $event->setCancelled(true); } Thanks @Sandertv!