For example, in ordinary tasks to get ID this way, but what about Async? $task = self::$plugin->getServer()->getScheduler()->scheduleDelayedTask(new TPTask(self::$plugin, $player), 20 * 60 * 5); $task->getTaskId();
The question is, why do you want to? Remember that you can't schedule AsyncTask like you cancel a repeating task.
PHP: <?phpdeclare(strict_types=1);namespace AsyncServerStatus;use pocketmine\scheduler\PluginTask;class AsyncServerTask extends PluginTask{ /** @var AsyncServerStatus */ private $plugin; private $asyncTaskId = -1; public function __construct(AsyncServerStatus $plugin) { parent::__construct($plugin); $this->plugin = $plugin; } public function onRun(int $currentTick): void { if (!$this->plugin->getServer()->getScheduler()->isQueued($this->asyncTaskId)) { // new AsyncTask $this->asyncTaskId = 202020020; // ID Task } }}
Why don't you toggle a boolean field in AsyncTask->onCompletion? You can store the AsyncServerTask instance with the task using AsyncTask->storeLocal.
The worker ID isn't useful for your scenario. Why do you need to use the task ID? What's wrong with using the AsyncTask instance itself?