Throw exception when attempting to save a non-generated chunk (#367)

This commit is contained in:
Dylan K. Taylor 2017-02-21 19:24:16 +00:00 committed by GitHub
parent c21197ef17
commit 282095513a
3 changed files with 14 additions and 6 deletions

View File

@ -992,7 +992,7 @@ class Level implements ChunkManager, Metadatable{
public function saveChunks(){
foreach($this->chunks as $chunk){
if($chunk->hasChanged()){
if($chunk->hasChanged() and $chunk->isGenerated()){
$this->provider->setChunk($chunk->getX(), $chunk->getZ(), $chunk);
$this->provider->saveChunk($chunk->getX(), $chunk->getZ());
$chunk->setChanged(false);
@ -2497,7 +2497,7 @@ class Level implements ChunkManager, Metadatable{
try{
if($chunk !== null){
if($trySave and $this->getAutoSave()){
if($trySave and $this->getAutoSave() and $chunk->isGenerated()){
$entities = 0;
foreach($chunk->getEntities() as $e){
if($e instanceof Player){

View File

@ -477,9 +477,13 @@ class LevelDB extends BaseLevelProvider{
return false;
}
public function saveChunk(int $x, int $z) : bool{
if($this->isChunkLoaded($x, $z)){
$this->writeChunk($this->getChunk($x, $z));
public function saveChunk(int $chunkX, int $chunkZ) : bool{
if($this->isChunkLoaded($chunkX, $chunkZ)){
$chunk = $this->getChunk($chunkX, $chunkZ);
if(!$chunk->isGenerated()){
throw new \InvalidStateException("Cannot save un-generated chunk");
}
$this->writeChunk($chunk);
return true;
}

View File

@ -309,7 +309,11 @@ class McRegion extends BaseLevelProvider{
public function saveChunk(int $chunkX, int $chunkZ) : bool{
if($this->isChunkLoaded($chunkX, $chunkZ)){
$this->getRegion($chunkX >> 5, $chunkZ >> 5)->writeChunk($this->getChunk($chunkX, $chunkZ));
$chunk = $this->getChunk($chunkX, $chunkZ);
if(!$chunk->isGenerated()){
throw new \InvalidStateException("Cannot save un-generated chunk");
}
$this->getRegion($chunkX >> 5, $chunkZ >> 5)->writeChunk($chunk);
return true;
}