mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
World: change 'closed' to 'unloaded'
this makes more sense overall from a reader's perspective. and also provide a rug-jerk for any idiots using World->close() when they aren't supposed to? ....
This commit is contained in:
parent
b8ebf8936e
commit
02fab77e55
@ -39,7 +39,7 @@ class Position extends Vector3{
|
|||||||
*/
|
*/
|
||||||
public function __construct($x, $y, $z, ?World $world){
|
public function __construct($x, $y, $z, ?World $world){
|
||||||
parent::__construct($x, $y, $z);
|
parent::__construct($x, $y, $z);
|
||||||
if($world !== null and $world->isClosed()){
|
if($world !== null and !$world->isLoaded()){
|
||||||
throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used");
|
throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class Position extends Vector3{
|
|||||||
* @throws AssumptionFailedError
|
* @throws AssumptionFailedError
|
||||||
*/
|
*/
|
||||||
public function getWorld() : World{
|
public function getWorld() : World{
|
||||||
if($this->world === null || $this->world->isClosed()){
|
if($this->world === null || !$this->world->isLoaded()){
|
||||||
throw new AssumptionFailedError("Position world is null or has been unloaded");
|
throw new AssumptionFailedError("Position world is null or has been unloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class Position extends Vector3{
|
|||||||
* Checks if this object has a valid reference to a loaded world
|
* Checks if this object has a valid reference to a loaded world
|
||||||
*/
|
*/
|
||||||
public function isValid() : bool{
|
public function isValid() : bool{
|
||||||
if($this->world !== null and $this->world->isClosed()){
|
if($this->world !== null and !$this->world->isLoaded()){
|
||||||
$this->world = null;
|
$this->world = null;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -285,7 +285,7 @@ class World implements ChunkManager{
|
|||||||
private $generator;
|
private $generator;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $closed = false;
|
private $unloaded = false;
|
||||||
/**
|
/**
|
||||||
* @var \Closure[]
|
* @var \Closure[]
|
||||||
* @phpstan-var array<int, \Closure() : void>
|
* @phpstan-var array<int, \Closure() : void>
|
||||||
@ -493,15 +493,15 @@ class World implements ChunkManager{
|
|||||||
return $this->worldId;
|
return $this->worldId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isClosed() : bool{
|
public function isLoaded() : bool{
|
||||||
return $this->closed;
|
return !$this->unloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function close() : void{
|
public function onUnload() : void{
|
||||||
if($this->closed){
|
if($this->unloaded){
|
||||||
throw new \InvalidStateException("Tried to close a world which is already closed");
|
throw new \InvalidStateException("Tried to close a world which is already closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +523,7 @@ class World implements ChunkManager{
|
|||||||
$this->provider = null;
|
$this->provider = null;
|
||||||
$this->blockCache = [];
|
$this->blockCache = [];
|
||||||
|
|
||||||
$this->closed = true;
|
$this->unloaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @phpstan-param \Closure() : void $callback */
|
/** @phpstan-param \Closure() : void $callback */
|
||||||
@ -747,7 +747,7 @@ class World implements ChunkManager{
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function doTick(int $currentTick) : void{
|
public function doTick(int $currentTick) : void{
|
||||||
if($this->closed){
|
if($this->unloaded){
|
||||||
throw new \InvalidStateException("Attempted to tick a world which has been closed");
|
throw new \InvalidStateException("Attempted to tick a world which has been closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,7 +1046,7 @@ class World implements ChunkManager{
|
|||||||
* @phpstan-var array<int, LightArray> $skyLight
|
* @phpstan-var array<int, LightArray> $skyLight
|
||||||
* @phpstan-var array<int, int> $heightMap
|
* @phpstan-var array<int, int> $heightMap
|
||||||
*/
|
*/
|
||||||
if($this->closed || ($chunk = $this->getChunk($chunkX, $chunkZ)) === null || $chunk->isLightPopulated() === true){
|
if($this->unloaded || ($chunk = $this->getChunk($chunkX, $chunkZ)) === null || $chunk->isLightPopulated() === true){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//TODO: calculated light information might not be valid if the terrain changed during light calculation
|
//TODO: calculated light information might not be valid if the terrain changed during light calculation
|
||||||
|
@ -168,7 +168,7 @@ class WorldManager{
|
|||||||
}
|
}
|
||||||
unset($this->worlds[$world->getId()]);
|
unset($this->worlds[$world->getId()]);
|
||||||
|
|
||||||
$world->close();
|
$world->onUnload();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ class WorldManager{
|
|||||||
*/
|
*/
|
||||||
public function findEntity(int $entityId) : ?Entity{
|
public function findEntity(int $entityId) : ?Entity{
|
||||||
foreach($this->worlds as $world){
|
foreach($this->worlds as $world){
|
||||||
assert(!$world->isClosed());
|
assert($world->isLoaded());
|
||||||
if(($entity = $world->getEntity($entityId)) instanceof Entity){
|
if(($entity = $world->getEntity($entityId)) instanceof Entity){
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ class PopulationTask extends AsyncTask{
|
|||||||
public function onCompletion() : void{
|
public function onCompletion() : void{
|
||||||
/** @var World $world */
|
/** @var World $world */
|
||||||
$world = $this->fetchLocal(self::TLS_KEY_WORLD);
|
$world = $this->fetchLocal(self::TLS_KEY_WORLD);
|
||||||
if(!$world->isClosed()){
|
if($world->isLoaded()){
|
||||||
$chunk = $this->chunk !== null ? FastChunkSerializer::deserialize($this->chunk) : null;
|
$chunk = $this->chunk !== null ? FastChunkSerializer::deserialize($this->chunk) : null;
|
||||||
|
|
||||||
for($i = 0; $i < 9; ++$i){
|
for($i = 0; $i < 9; ++$i){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user