Be less dependent on AsyncTask->onCompletion() Server parameter

this is going to get removed soon.
This commit is contained in:
Dylan K. Taylor 2018-08-04 15:56:14 +01:00
parent 779d92c656
commit 20f3b82d52
6 changed files with 27 additions and 26 deletions

View File

@ -133,7 +133,7 @@ class TimingsCommand extends VanillaCommand{
}
$result = $this->getResult()[0];
if($result instanceof \RuntimeException){
$server->getLogger()->logException($result);
$sender->getServer()->getLogger()->logException($result);
return;
}
if(isset($result[0]) && is_array($response = json_decode($result[0], true)) && isset($response["id"])){

View File

@ -53,6 +53,8 @@ class PopulationTask extends AsyncTask{
foreach($level->getAdjacentChunks($chunk->getX(), $chunk->getZ()) as $i => $c){
$this->{"chunk$i"} = $c !== null ? $c->fastSerialize() : null;
}
$this->storeLocal($level);
}
public function onRun() : void{
@ -136,8 +138,9 @@ class PopulationTask extends AsyncTask{
}
public function onCompletion(Server $server) : void{
$level = $server->getLevel($this->levelId);
if($level !== null){
/** @var Level $level */
$level = $this->fetchLocal();
if(!$level->isClosed()){
if(!$this->state){
$level->registerGeneratorToWorker($this->worker->getAsyncWorkerId());
}

View File

@ -30,11 +30,10 @@ use pocketmine\Server;
class LightPopulationTask extends AsyncTask{
public $levelId;
public $chunk;
public function __construct(Level $level, Chunk $chunk){
$this->levelId = $level->getId();
$this->storeLocal($level);
$this->chunk = $chunk->fastSerialize();
}
@ -50,8 +49,9 @@ class LightPopulationTask extends AsyncTask{
}
public function onCompletion(Server $server){
$level = $server->getLevel($this->levelId);
if($level !== null){
/** @var Level $level */
$level = $this->fetchLocal();
if(!$level->isClosed()){
/** @var Chunk $chunk */
$chunk = Chunk::fastDeserialize($this->chunk);
$level->generateChunkCallback($chunk->getX(), $chunk->getZ(), $chunk);

View File

@ -31,8 +31,6 @@ use pocketmine\Server;
use pocketmine\tile\Spawnable;
class ChunkRequestTask extends AsyncTask{
/** @var int */
protected $levelId;
/** @var string */
protected $chunk;
/** @var int */
@ -45,7 +43,7 @@ class ChunkRequestTask extends AsyncTask{
protected $compressionLevel;
public function __construct(Level $level, int $chunkX, int $chunkZ, Chunk $chunk){
$this->levelId = $level->getId();
$this->storeLocal($level);
$this->compressionLevel = NetworkCompression::$LEVEL;
$this->chunk = $chunk->fastSerialize();
@ -78,15 +76,14 @@ class ChunkRequestTask extends AsyncTask{
}
public function onCompletion(Server $server) : void{
$level = $server->getLevel($this->levelId);
if($level instanceof Level){
/** @var Level $level */
$level = $this->fetchLocal();
if(!$level->isClosed()){
if($this->hasResult()){
$level->chunkRequestCallback($this->chunkX, $this->chunkZ, $this->getResult());
}else{
$server->getLogger()->error("Chunk request for level #" . $this->levelId . ", x=" . $this->chunkX . ", z=" . $this->chunkZ . " doesn't have any result data");
$level->getServer()->getLogger()->error("Chunk request for level " . $level->getName() . ", x=" . $this->chunkX . ", z=" . $this->chunkZ . " doesn't have any result data");
}
}else{
$server->getLogger()->debug("Dropped chunk task due to level not loaded");
}
}
}

View File

@ -53,6 +53,10 @@ class AutoUpdater{
}
}
public function checkUpdateError(string $error) : void{
$this->server->getLogger()->debug("[AutoUpdater] Async update check failed due to \"$error\"");
}
/**
* Callback used at the end of the update checking task
*
@ -146,7 +150,7 @@ class AutoUpdater{
* Schedules an AsyncTask to check for an update.
*/
public function doCheck(){
$this->server->getAsyncPool()->submitTask(new UpdateCheckTask($this->endpoint, $this->getChannel()));
$this->server->getAsyncPool()->submitTask(new UpdateCheckTask($this, $this->endpoint, $this->getChannel()));
}
/**

View File

@ -38,7 +38,8 @@ class UpdateCheckTask extends AsyncTask{
/** @var string */
private $error = "Unknown error";
public function __construct(string $endpoint, string $channel){
public function __construct(AutoUpdater $updater, string $endpoint, string $channel){
$this->storeLocal($updater);
$this->endpoint = $endpoint;
$this->channel = $channel;
}
@ -72,16 +73,12 @@ class UpdateCheckTask extends AsyncTask{
}
public function onCompletion(Server $server){
if($this->error !== ""){
$server->getLogger()->debug("[AutoUpdater] Async update check failed due to \"$this->error\"");
/** @var AutoUpdater $updater */
$updater = $this->fetchLocal();
if($this->hasResult()){
$updater->checkUpdateCallback($this->getResult());
}else{
$updateInfo = $this->getResult();
if(is_array($updateInfo)){
$server->getUpdater()->checkUpdateCallback($updateInfo);
}else{
$server->getLogger()->debug("[AutoUpdater] Update info error");
}
$updater->checkUpdateError($this->error);
}
}
}