I want to make a countdown kind of thing like 10.. 9.. 8.. 3.. 2.. 1 but it's not repeating again when I tried it my attempt: PHP: class DropParty extends PluginTask{ public function __construct(Main $plugin) { parent::__construct($plugin); $this->plugin = $plugin; $this->close = false; $this->seconds = 15; } public function close() { $this->close = true; } public function onRun($tick) { switch ($this->seconds) { case 15: $this->plugin->getLogger()->info("Triggered"); break; case 3: $this->plugin->getServer()->broadcastMessage("drop party in 3"); break; case 2: $this->plugin->getServer()->broadcastMessage("drop party in 2"); break; case 1: $this->plugin->getServer()->broadcastMessage("drop party in 1"); break; case 0: $this->plugin->getServer()->broadcastMessage("WOOOOOOOOOOOOOOOOOOSH!"); break; } $this->seconds--; }} this is in my main class onEnable PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(new DropParty($this), 1 * 20); I get this working after I restart the server but it doesn't repeat.. only repeat if I restart the server again
} foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player) { if($time === 20) { // every 20 ticks is one second $player->sendMessage("drop party in 3"); $click = new ClickSound($player); $player->getLevel()->addSound($click); } if($time === 40) { $player->sendMessage("drop party in 2"); $click = new ClickSound($player); $player->getLevel()->addSound($click); } if($time === 60) { $player->sendMessage("drop party in 1"); $click = new ClickSound($player); $player->getLevel()->addSound($click); } if($time === 80) { $player->sendMessage("WOOOOOOOOOOOOOOOOOOSH!"); $player->getLevel()->addSound(new AnvilUseSound($pl)); }
Hmm, to help you... I will ask one simply question... What happens once $this->seconds is less than 0? you never set the time back up to 15 that should fix your issue
PHP: class DropParty extends PluginTask{ public function __construct(Main $plugin) { parent::__construct($plugin); $this->plugin = $plugin; $this->close = false; $this->seconds = 15; } public function close() { $this->close = true; } public function onRun($tick) { switch ($this->seconds) { case 15: $this->plugin->getLogger()->info("Triggered"); break; case 3: $this->plugin->getServer()->broadcastMessage("drop party in 3"); break; case 2: $this->plugin->getServer()->broadcastMessage("drop party in 2"); break; case 1: $this->plugin->getServer()->broadcastMessage("drop party in 1"); break; case 0: $this->plugin->getServer()->broadcastMessage("WOOOOOOOOOOOOOOOOOOSH!"); $this->seconds = 15; break; } $this->seconds--; }}