Hi all. I wonder how it is possible to obtain the number of the traversed time PluginTask, that is, from the beginning to the end and bring this time?
Since you haven't provided a unit time, I'll be ignoring unit time too. Method 1 of ∞: PHP: class A extends PluginTask { private $firstTick; public function onRun(int $tick){ if($this->firstTick === null){ $this->firstTick = $tick; } $ticksElapsed = $tick - $this->firstTick; }} Method 2 of ∞: PHP: //declare global variable $initialTime//in the constructor, set $initialTime's value to time()//to find the time elapsed, subtract time() with $initialTime Your question was to get the end time of the task, I am assuming you are using a no-break repeating task. In that case you can set the task to a variable before scheduling the task, and create a public variable, or a function to fetch the elapsed time. PHP: /** @var Plugin $plugin */$task = new MyPluginTask($plugin);$plugin->getServer()->getScheduler()->scheduleRepeatingTask($task, 20);//Getting time before cancelling the task:$time = $task->getTimeElapsed();$plugin->getServer()->getScheduler()->cancelTask($task->getTaskId());
Use class properties, not global variables... Never declare any named values in the global scope. If you have to (e.g. thread store keys, stream wrapper names), use the plugin namespace as the prefix.