You can schedule the task with PHP: PluginBase::getServer()->getScheduler()->scheduleDelayedTask(new TaskObject($this, $player), $delay = 20); In the Task class, you can construct it like this: PHP: <?php use pocketmine\Player; use pocketmine\scheduler\PluginTask; use pocketmine\entity\Effect; class TaskObject extends PluginTask{ private $plugin; public function __construct(Main $plugin, Player $player){ parent::__construct($plugin); $this->plugin = $plugin; $this->player = $player; } public function onRun($tick){ $this->player->addEffect(/*Your effect*/); //Anything here will be run approximately 1 second after the PlayerRespawnEvent is called. } }
Then come this error Code: [Server] [PocketMine] > Could not execute task Main\EffectTask: Argument 1 passed to pocketmine\Player::addEffect() must be an instance of pocketmine\entity\Effect, integer given, called in /storage/emulated/0/PocketMine/plugins/Test/src/Main/Test.php on line 245 [Server] [PocketMine] > TypeError: "Argument 1 passed to pocketmine\Player::addEffect() must be an instance of pocketmine\entity\Effect, integer given, called in /storage/emulated/0/PocketMine/plugins/Test/src/Main/Test.php on line 245" (EXCEPTION) in "/src/pocketmine/Player" at line 4070 Line 244 - 245 PHP: public function onRun($tick){ $this->player->addEffect(Effect::JUMP);
Use this to define an effect: PHP: Effect::getEffect(Effect::JUMP); You can also set amplifier and duration (in ticks) with $effect->setAmplifier() and $effect->setDuration().
Note that you're better off passing the name of a player to a task, instead of the player object. If you don't do it, it'll use the player data from the moment the task got scheduled, which means it's no longer tracking the player. Once you have the player name in the task, you can use $server->getPlayer($this->name);
Basic OOP: Objects are, unless cloned, passed by implicit memory reference, i.e. the data of an object will always be the same set of data unless it is cloned. Unless it is a new player (rejoined), which is probably not what you want. However it is a good idea not to persist the player object to prevent memory leak, as player instance should no longer be referenced anywhere after player quit.