mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Level: Removed WeakPosition
This is a bad fix for an issue found in one specific use-case. This is redundant because the only places this is used are places where it's guaranteed to be valid, or places where it is checked to be valid anyway. The Level leak originally noted that led to the creation of this class is something I consider to be a non-issue, because all the heavy things will be cleaned up anyway.
This commit is contained in:
parent
73e09392b6
commit
403e996d2f
@ -86,7 +86,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
|
||||
@ -1166,7 +1165,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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1181,7 +1180,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();
|
||||
@ -2099,9 +2098,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user