There is no error but task doesn't work. It should be delayed 4second and do Start() here is code PHP: use pocketmine\scheduler\Task;class Run extends PluginBase implements Listener{public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { $command = $command->getName(); $sender = $sender->getPlayer(); if ( $command == "tea"){ $task = new time; $this->getScheduler()->scheduleDelayedTask($task, 80); $this->Start(); }return true; } PHP: class time extends Task{ public function onRun($currentTick){ }}
You must add function Run->Start(); to onRun() function, your code will execute the function without delay.
if you want to check sender class use if(instanceof) public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ if($command->getName() == "tea"){ if($sender instanceof Player){ $this->getScheduler()->scheduleDelayedTask(new time($this), 20 * 4); return true; } } } use path_to_your_main_class\main_class_name; use pocketmine\scheduler\Task; class time extends Task{ public function __construct(main_class_name $main){ $this->main = $main; } public function onRun($currentTick){ $this->main->Start(); //calling start() function from main class } }
Then, It can only work with that I writen in onRun() ??? I think that is not efficient.. Then When I need to use many tasks, Should I need to make new tasks and put methods individually what I want to delay?? Is there only that way?
Love the fact that you can code, but can't use BBCode for your code. Let me explain the code you wrote: I suggest you to go over the code and see if it makes sense.