Hey. Is it possible to cancel a task for only one player? With this code I cancel it normally. PHP: $this->getOwner()->getServer()->getScheduler()->cancelTask($this->getTaskId());
I started it using this: PHP: $task = new ChestTask($this, $player); $this->getServer()->getScheduler()->scheduleRepeatingTask($task, 20);
you can have the task check the plugin for players in an array and only run using an if statement in the task
I have a countdown. If the player did something he starts the task. But if another player starts the a countdown and the first player stopped his countdown, the second countdown also stops
This should work for onRun() PHP: foreach($this->plugin->counting as $player) { if($player === $this->player) { return; } #run the task}
I'm searching for something like this PHP: $this->getOwner()->getServer()->getScheduler()->cancelTask($this->getTaskId(), $player); I already have a own countdown for each player
this looks like you add seperate tasks for each player that activated it then just this PHP: $this->getOwner()->getServer()->getScheduler()->cancelTask($this->getTaskId()); should work fine
But I use foreach and getOnlinePlayers to define $player. Do I need to get the player from where I start the task?
My way of doing this, if it's a delayed task - pass a player name to Task, don't pass Player object. Now on Task::onRun() get the Player object by calling Server::getPlayer() run through null check and execute a code. If you do not understand what I just said, give up. How do you know which player to pick? (username, eID, UUID, ClientID etc.)
I use this code: PHP: class ChestCloseTask extends PluginTask {public $sec = array(); public function __construct(Plugin $owner){ parent::__construct($owner); } public function onRun($currentTick) { $players = $this->getOwner()->getServer()->getDefaultLevel()->getPlayers(); foreach ($players as $player) {$name = $player->getName(); if($this->getOwner()->sec[$name] >= 1) { $this->getOwner()->sec[$name] = --$this->getOwner()->sec[$name]; But how can I stop it for each player?
And if the timer is at 0 set it to -1?? Or what ist Player record? PHP: if($player->countdown != -1){}