Merge branch 'remove-weak-position'

This commit is contained in:
Dylan K. Taylor 2018-05-10 13:53:07 +01:00
commit b8523cb304
3 changed files with 12 additions and 97 deletions

View File

@ -87,7 +87,6 @@ use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\Location;
use pocketmine\level\Position;
use pocketmine\level\WeakPosition;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\metadata\MetadataValue;
@ -299,7 +298,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var Vector3|null */
protected $sleeping = null;
/** @var WeakPosition|null */
/** @var Position|null */
private $spawnPosition = null;
//TODO: Abilities
@ -1168,7 +1167,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @return bool
*/
public function hasValidSpawnPosition() : bool{
return $this->spawnPosition instanceof WeakPosition and $this->spawnPosition->isValid();
return $this->spawnPosition !== null and $this->spawnPosition->isValid();
}
/**
@ -1183,7 +1182,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}else{
$level = $pos->getLevel();
}
$this->spawnPosition = new WeakPosition($pos->x, $pos->y, $pos->z, $level);
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
$pk = new SetSpawnPositionPacket();
$pk->x = $this->spawnPosition->getFloorX();
$pk->y = $this->spawnPosition->getFloorY();
@ -2083,9 +2082,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(!$this->hasValidSpawnPosition()){
if(($level = $this->server->getLevelByName($this->namedtag->getString("SpawnLevel", ""))) instanceof Level){
$this->spawnPosition = new WeakPosition($this->namedtag->getInt("SpawnX"), $this->namedtag->getInt("SpawnY"), $this->namedtag->getInt("SpawnZ"), $level);
$this->spawnPosition = new Position($this->namedtag->getInt("SpawnX"), $this->namedtag->getInt("SpawnY"), $this->namedtag->getInt("SpawnZ"), $level);
}else{
$this->spawnPosition = WeakPosition::fromObject($this->level->getSafeSpawn());
$this->spawnPosition = $this->level->getSafeSpawn();
}
}

View File

@ -94,7 +94,13 @@ class Position extends Vector3{
* @return bool
*/
public function isValid() : bool{
return $this->getLevel() instanceof Level;
if($this->level !== null and $this->level->isClosed()){
$this->level = null;
return false;
}
return $this->level !== null;
}
/**

View File

@ -1,90 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\level;
use pocketmine\math\Vector3;
use pocketmine\Server;
class WeakPosition extends Position{
protected $levelId = -1;
/**
* @param int $x
* @param int $y
* @param int $z
* @param Level $level
*/
public function __construct($x = 0, $y = 0, $z = 0, Level $level = null){
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->levelId = ($level !== null ? $level->getId() : -1);
}
public static function fromObject(Vector3 $pos, Level $level = null){
return new WeakPosition($pos->x, $pos->y, $pos->z, $level);
}
/**
* @return Level|null
*/
public function getLevel(){
return Server::getInstance()->getLevel($this->levelId);
}
/**
* @param Level|null $level
*
* @return $this
*
* @throws \InvalidArgumentException if the specified Level has been closed
*/
public function setLevel(Level $level = null){
if($level !== null and $level->isClosed()){
throw new \InvalidArgumentException("Specified level has been unloaded and cannot be used");
}
$this->levelId = ($level !== null ? $level->getId() : -1);
return $this;
}
/**
* Returns a side Vector
*
* @param int $side
* @param int $step
*
* @return WeakPosition
*/
public function getSide(int $side, int $step = 1){
assert($this->isValid());
return WeakPosition::fromObject(parent::getSide($side, $step), $this->level);
}
public function __toString(){
return "Weak" . parent::__toString();
}
}