mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 05:34:54 +00:00
Added LevelAPI::unloadLevel(Level $level)
This commit is contained in:
parent
72f8f00c5d
commit
b39677cc96
@ -121,6 +121,28 @@ class LevelAPI{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function unloadLevel(Level $level){
|
||||||
|
$name = $level->getName();
|
||||||
|
if($name === $this->default){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$level->nextSave = PHP_INT_MAX;
|
||||||
|
$level->save();
|
||||||
|
foreach($this->server->api->player->getAll($level) as $player){
|
||||||
|
$player->teleport($this->server->spawn);
|
||||||
|
}
|
||||||
|
foreach($this->server->api->entity->getAll($level) as $entity){
|
||||||
|
if($entity->class !== ENTITY_PLAYER){
|
||||||
|
$entity->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($this->server->api->tileentity->getAll($level) as $tile){
|
||||||
|
$tile->close();
|
||||||
|
}
|
||||||
|
unset($this->levels[$name]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function loadLevel($name){
|
public function loadLevel($name){
|
||||||
if($this->get($name) !== false){
|
if($this->get($name) !== false){
|
||||||
return true;
|
return true;
|
||||||
|
@ -658,7 +658,7 @@ class Player{
|
|||||||
}
|
}
|
||||||
if($terrain === true){
|
if($terrain === true){
|
||||||
$this->orderChunks();
|
$this->orderChunks();
|
||||||
$this->getNextChunk();
|
$this->getNextChunk(false);
|
||||||
}
|
}
|
||||||
$this->entity->check = true;
|
$this->entity->check = true;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Level{
|
class Level{
|
||||||
public $entities, $tileEntities;
|
public $entities, $tileEntities, $nextSave;
|
||||||
private $level, $time, $startCheck, $startTime, $server, $name, $usedChunks, $nextSave, $changedBlocks, $changedCount;
|
private $level, $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount;
|
||||||
|
|
||||||
public function __construct(PMFLevel $level, Config $entities, Config $tileEntities, $name){
|
public function __construct(PMFLevel $level, Config $entities, Config $tileEntities, $name){
|
||||||
$this->server = ServerAPI::request();
|
$this->server = ServerAPI::request();
|
||||||
@ -103,13 +103,13 @@ class Level{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->nextSave < $now and $this->server->saveEnabled === true){
|
if($this->nextSave < $now){
|
||||||
foreach($this->usedChunks as $i => $c){
|
foreach($this->usedChunks as $i => $c){
|
||||||
if(count($c) === 0){
|
if(count($c) === 0){
|
||||||
unset($this->usedChunks[$i]);
|
unset($this->usedChunks[$i]);
|
||||||
$X = explode(".", $i);
|
$X = explode(".", $i);
|
||||||
$Z = array_pop($X);
|
$Z = array_pop($X);
|
||||||
$this->level->unloadChunk((int) array_pop($X), (int) $Z);
|
$this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->save();
|
$this->save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user