Hey,I was trying to make a cosmetic for my server(colorful armor) and it worked after some tries but I don't know how to "turn it off",I mean I don't know how to cancel the colorful armor task with the result of the armor stop sending to player,I have just found and know how to cancel all tasks to all players but not a certain task for a player PHP: case "on": $colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); //close possible task $this->plugin->getScheduler()->cancelTask($colorfularmortask->getTaskId()); //use task $colorfularmorhandler = $this->plugin->getScheduler()->scheduleRepeatingTask($colorfularmortask, 20); //$colorfularmortask->setHandler($colorfularmorhandler); return true; case "off": $sender->getArmorInventory()->clearAll(); $this->plugin->getScheduler()->cancelAllTasks($this->plugin, $sender); //doesn't work idk /**$colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); $this->plugin->getScheduler()->cancelTask($colorfularmortask->getTaskId());*/ return true; } The task works fine but I can't understand how to cancel it,I would like some help if its possible.
Save The Task Id public $taskIds = []; $task = ....//YOUR TASK $this->taskIds[$player->getName()] = $task; //To cancel $this->getScheduler()->cancelTask($this->taskIds[$player->getName()]->getTaskId());
PHP: $colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); $this->taskIds[$sender->getName()] = $colorfularmortask; $this->plugin->getScheduler()->cancelTask($this->taskIds[$sender->getName()]->getTaskId()); Like that?Because it doesn't work.
PHP: register the public $taskId = [];case "on": $colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); //close possible task //use task $colorfularmorhandler = $this->plugin->getScheduler()->scheduleRepeatingTask($colorfularmortask, 20); $this->taskId[$sender->getName()] = $colorfularmorhandler; //$colorfularmortask->setHandler($colorfularmorhandler); return true; case "off": $sender->getArmorInventory()->clearAll(); if(isset(($task = $this->taskId[$sender->getName()]))){ $this->plugin->getScheduler()->cancelTask($task->getTaskId()); } //doesn't work idk /**$colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); $this->plugin->getScheduler()->cancelTask($colorfularmortask->getTaskId());*/ return true; }
sorry, please edit this code PHP: if(isset(($task = $this->taskId[$sender->getName()]))){ $this->plugin->getScheduler()->cancelTask($task->getTaskId()); } to PHP: if(isset($this->taskId[$sender->getName()])){$task = $this->taskId[$sender->getName()];$this->getServer()->getScheduler()->cancelTask($task->getId());}
PHP: if ($sender instanceof Player) { if(isset($args[0])) { switch($args[0]) { case "on": $colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); //use task $colorfularmorhandler = $this->plugin->getScheduler()->scheduleRepeatingTask($colorfularmortask, 20); $this->taskId[$sender->getName()] = $colorfularmorhandler; //$colorfularmortask->setHandler($colorfularmorhandler); return true; case "off": $sender->getArmorInventory()->clearAll(); $colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); $this->taskId[$sender->getName()] = $colorfularmortask; if(isset($this->taskId[$sender->getName()])){$colorfularmortask = $this->taskId[$sender->getName()];$this->plugin->getScheduler()->cancelTask($colorfularmortask->getTaskId()); } /**$this->plugin->getScheduler()->cancelAllTasks($this->plugin, $sender); //doesn't work idk $colorfularmortask = new ColorfulArmorTask($this->plugin, $sender); $this->plugin->getScheduler()->cancelTask($colorfularmortask->getTaskId());*/ return true; } } else { $sender->sendMessage("§c/colorfularmor <on: off>"); return true; } } if ($sender instanceof ConsoleCommandSender) { $sender->sendMessage("Run this command in-game!"); return true; } } Ok isset error doesn't exist now,but task still doesn't stop.