1: <?php
2: namespace aliuly\common;
3: use pocketmine\plugin\Plugin;
4: use pocketmine\scheduler\AsyncTask;
5: use pocketmine\Server;
6:
7:
8: 9: 10: 11:
12: abstract class PluginAsyncTask extends AsyncTask{
13:
14: public $owner;
15:
16:
17: protected $callable;
18:
19:
20: protected $args;
21:
22: 23: 24: 25: 26:
27: public function __construct(Plugin $owner, $callable, array $args = []){
28: $this->owner = $owner->getName();
29: $this->callable = $callable;
30: $this->args = $args;
31: }
32: public function onCompletion(Server $server) {
33: $plugin = $server->getPluginManager()->getPlugin($this->owner);
34: if ($plugin == null) {
35: $server->getLogger()->error("Internal ERROR: ".__METHOD__.",".__LINE__);
36: return;
37: }
38: if (!$plugin->isEnabled()) return;
39: $callback = [$plugin, $this->callable];
40: $callback($this->getResult(),...$this->args);
41: }
42: }
43: