LevelProvider: Remove redundant method requestChunkTask()

This removes one more dependency that LevelProvider has on Level.
This commit is contained in:
Dylan K. Taylor 2017-12-31 14:51:06 +00:00
parent 7264ce43ae
commit 8a3f8b4706
3 changed files with 8 additions and 25 deletions

View File

@ -47,8 +47,10 @@ use pocketmine\event\Timings;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\format\ChunkException;
use pocketmine\level\format\EmptySubChunk; use pocketmine\level\format\EmptySubChunk;
use pocketmine\level\format\io\BaseLevelProvider; use pocketmine\level\format\io\BaseLevelProvider;
use pocketmine\level\format\io\ChunkRequestTask;
use pocketmine\level\format\io\LevelProvider; use pocketmine\level\format\io\LevelProvider;
use pocketmine\level\generator\GenerationTask; use pocketmine\level\generator\GenerationTask;
use pocketmine\level\generator\Generator; use pocketmine\level\generator\Generator;
@ -2544,8 +2546,12 @@ class Level implements ChunkManager, Metadatable{
} }
$this->timings->syncChunkSendPrepareTimer->startTiming(); $this->timings->syncChunkSendPrepareTimer->startTiming();
$task = $this->provider->requestChunkTask($x, $z); $chunk = $this->provider->getChunk($x, $z, false);
$this->server->getScheduler()->scheduleAsyncTask($task); if(!($chunk instanceof Chunk)){
throw new ChunkException("Invalid Chunk sent");
}
$this->server->getScheduler()->scheduleAsyncTask(new ChunkRequestTask($this, $chunk));
$this->timings->syncChunkSendPrepareTimer->stopTiming(); $this->timings->syncChunkSendPrepareTimer->stopTiming();
} }

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace pocketmine\level\format\io; namespace pocketmine\level\format\io;
use pocketmine\level\format\Chunk;
use pocketmine\level\format\ChunkException;
use pocketmine\level\generator\Generator; use pocketmine\level\generator\Generator;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\level\LevelException; use pocketmine\level\LevelException;
@ -32,7 +30,6 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\BigEndianNBTStream; use pocketmine\nbt\BigEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
use pocketmine\scheduler\AsyncTask;
abstract class BaseLevelProvider implements LevelProvider{ abstract class BaseLevelProvider implements LevelProvider{
/** @var Level */ /** @var Level */
@ -127,13 +124,4 @@ abstract class BaseLevelProvider implements LevelProvider{
$buffer = $nbt->writeCompressed(); $buffer = $nbt->writeCompressed();
file_put_contents($this->getPath() . "level.dat", $buffer); file_put_contents($this->getPath() . "level.dat", $buffer);
} }
public function requestChunkTask(int $x, int $z) : AsyncTask{
$chunk = $this->getChunk($x, $z, false);
if(!($chunk instanceof Chunk)){
throw new ChunkException("Invalid Chunk sent");
}
return new ChunkRequestTask($this->level, $chunk);
}
} }

View File

@ -26,7 +26,6 @@ namespace pocketmine\level\format\io;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\scheduler\AsyncTask;
interface LevelProvider{ interface LevelProvider{
@ -161,16 +160,6 @@ interface LevelProvider{
*/ */
public function isChunkPopulated(int $chunkX, int $chunkZ) : bool; public function isChunkPopulated(int $chunkX, int $chunkZ) : bool;
/**
* Requests a MC: PE network chunk to be sent
*
* @param int $x
* @param int $z
*
* @return AsyncTask
*/
public function requestChunkTask(int $x, int $z) : AsyncTask;
/** /**
* @return string * @return string
*/ */