Skip to content

Instantly share code, notes, and snippets.

@SOF3
Last active November 20, 2016 10:19
Show Gist options
  • Save SOF3/dbd4cf6378dc57087f91dae5ea7d1706 to your computer and use it in GitHub Desktop.
Save SOF3/dbd4cf6378dc57087f91dae5ea7d1706 to your computer and use it in GitHub Desktop.
<?php
class MigrateDatabaseTask extends AsyncTask{
public function __construct(MigrateProgress $progress){
parent::__construct($progress);
}
public function onRun(){
$input = new InputDataIterator();
$output = new OutputWriter();
foreach($input as $datum){
$output->write($datum);
$this->publishProgress($output->writtenSize() / $input->totalSize());
}
}
public function onProgressUpdate(Server $server, float $progress){
$this->peekLocal($server)->progress = $progress;
}
public function onCompletion(Server $server){
$this->fetchLocal($server); // even if we don't use it, we still have to call this, or a NOTICE will be generated.
}
}
class MigrateProgress{
public $progress;
}
class MigarteInfoTask extends PluginTask{
public $progress;
public $player;
public function onRun($ticks){
if(!isset($this->player)) return;
if(!$this->player->isOnline()) {
unset($this->player);
return;
}
$this->player->sendPopup("Progress: {$this->progress->progress}");
}
}
$task = new MigrateProgress($main);
$task->progress = new MigrateProgress;
$task->player = $player;
$scheduler->scheduleRepeatingTask($task, 20);
$scheduler->scheduleAsyncTask(new MigrateDatabaseTask($task->progress));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment