mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 23:44:17 +00:00
Task: Remove currentTick parameter (#3498)
This parameter is not used for the vast majority of task use cases and just serves as extra useless boilerplate code, especially for closure-based tasks. This use case can be replaced using Server->getTick() in the cases where it matters.
This commit is contained in:
parent
38e28f91e8
commit
67666db827
@ -32,8 +32,8 @@ use pocketmine\utils\Utils;
|
||||
* Example usage:
|
||||
*
|
||||
* ```
|
||||
* TaskScheduler->scheduleTask(new CancellableClosureTask(function(int $currentTick) : bool{
|
||||
* echo "HI on $currentTick\n";
|
||||
* TaskScheduler->scheduleTask(new CancellableClosureTask(function() : bool{
|
||||
* echo "HI\n";
|
||||
* $continue = false;
|
||||
* return $continue; //stop repeating
|
||||
* });
|
||||
@ -47,20 +47,20 @@ class CancellableClosureTask extends Task{
|
||||
|
||||
/**
|
||||
* @var \Closure
|
||||
* @phpstan-var \Closure(int $currentTick) : bool
|
||||
* @phpstan-var \Closure() : bool
|
||||
*/
|
||||
private $closure;
|
||||
|
||||
/**
|
||||
* CancellableClosureTask constructor.
|
||||
*
|
||||
* The closure should follow the signature callback(int $currentTick) : bool. The return value will be used to
|
||||
* The closure should follow the signature callback() : bool. The return value will be used to
|
||||
* decide whether to continue repeating.
|
||||
*
|
||||
* @phpstan-param \Closure(int $currentTick) : bool $closure
|
||||
* @phpstan-param \Closure() : bool $closure
|
||||
*/
|
||||
public function __construct(\Closure $closure){
|
||||
Utils::validateCallableSignature(function(int $currentTick) : bool{ return false; }, $closure);
|
||||
Utils::validateCallableSignature(function() : bool{ return false; }, $closure);
|
||||
$this->closure = $closure;
|
||||
}
|
||||
|
||||
@ -68,8 +68,8 @@ class CancellableClosureTask extends Task{
|
||||
return Utils::getNiceClosureName($this->closure);
|
||||
}
|
||||
|
||||
public function onRun(int $currentTick) : void{
|
||||
if(!($this->closure)($currentTick)){
|
||||
public function onRun() : void{
|
||||
if(!($this->closure)()){
|
||||
$this->getHandler()->cancel();
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ use pocketmine\utils\Utils;
|
||||
* Example usage:
|
||||
*
|
||||
* ```
|
||||
* TaskScheduler->scheduleTask(new ClosureTask(function(int $currentTick) : void{
|
||||
* echo "HI on $currentTick\n";
|
||||
* TaskScheduler->scheduleTask(new ClosureTask(function() : void{
|
||||
* echo "HI\n";
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@ -40,16 +40,16 @@ class ClosureTask extends Task{
|
||||
|
||||
/**
|
||||
* @var \Closure
|
||||
* @phpstan-var \Closure(int) : void
|
||||
* @phpstan-var \Closure() : void
|
||||
*/
|
||||
private $closure;
|
||||
|
||||
/**
|
||||
* @param \Closure $closure Must accept only ONE parameter, $currentTick
|
||||
* @phpstan-param \Closure(int) : void $closure
|
||||
* @param \Closure $closure Must accept zero parameters
|
||||
* @phpstan-param \Closure() : void $closure
|
||||
*/
|
||||
public function __construct(\Closure $closure){
|
||||
Utils::validateCallableSignature(function(int $currentTick) : void{}, $closure);
|
||||
Utils::validateCallableSignature(function() : void{}, $closure);
|
||||
$this->closure = $closure;
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ class ClosureTask extends Task{
|
||||
return Utils::getNiceClosureName($this->closure);
|
||||
}
|
||||
|
||||
public function onRun(int $currentTick) : void{
|
||||
($this->closure)($currentTick);
|
||||
public function onRun() : void{
|
||||
($this->closure)();
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ abstract class Task{
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function onRun(int $currentTick);
|
||||
abstract public function onRun();
|
||||
|
||||
/**
|
||||
* Actions to execute if the Task is cancelled
|
||||
|
@ -116,10 +116,10 @@ class TaskHandler{
|
||||
$this->task->setHandler(null);
|
||||
}
|
||||
|
||||
public function run(int $currentTick) : void{
|
||||
public function run() : void{
|
||||
$this->timings->startTiming();
|
||||
try{
|
||||
$this->task->onRun($currentTick);
|
||||
$this->task->onRun();
|
||||
}finally{
|
||||
$this->timings->stopTiming();
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ class TaskScheduler{
|
||||
unset($this->tasks[$task->getTaskId()]);
|
||||
continue;
|
||||
}
|
||||
$task->run($this->currentTick);
|
||||
$task->run();
|
||||
if($task->isRepeating()){
|
||||
$task->setNextRun($this->currentTick + $task->getPeriod());
|
||||
$this->queue->insert($task, $this->currentTick + $task->getPeriod());
|
||||
|
@ -34,7 +34,7 @@ class CheckTestCompletionTask extends Task{
|
||||
$this->plugin = $plugin;
|
||||
}
|
||||
|
||||
public function onRun(int $currentTick){
|
||||
public function onRun(){
|
||||
$test = $this->plugin->getCurrentTest();
|
||||
if($test === null){
|
||||
if(!$this->plugin->startNextTest()){
|
||||
|
Loading…
x
Reference in New Issue
Block a user