Fixed wasteful throwaway objects used for spawn positions

This commit is contained in:
Dylan K. Taylor 2018-01-02 12:21:11 +00:00
parent d30a6b60b7
commit 9a956692de
2 changed files with 9 additions and 5 deletions

View File

@ -1102,8 +1102,9 @@ class Server{
$this->getLogger()->notice($this->getLanguage()->translateString("pocketmine.level.backgroundGeneration", [$name]));
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$spawnLocation = $level->getSpawnLocation();
$centerX = $spawnLocation->x >> 4;
$centerZ = $spawnLocation->z >> 4;
$order = [];

View File

@ -1711,7 +1711,9 @@ class Level implements ChunkManager, Metadatable{
public function checkSpawnProtection(Player $player, Vector3 $vector) : bool{
if(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){
$t = new Vector2($vector->x, $vector->z);
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
$spawnLocation = $this->getSpawnLocation();
$s = new Vector2($spawnLocation->x, $spawnLocation->z);
if(count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance){
return true;
}
@ -2811,8 +2813,9 @@ class Level implements ChunkManager, Metadatable{
* @return bool
*/
public function isSpawnChunk(int $X, int $Z) : bool{
$spawnX = $this->provider->getSpawn()->getX() >> 4;
$spawnZ = $this->provider->getSpawn()->getZ() >> 4;
$spawn = $this->provider->getSpawn();
$spawnX = $spawn->x >> 4;
$spawnZ = $spawn->z >> 4;
return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1;
}