I made this small plugin which basically sends a bunch of titles after one another but I have used the sleep function thingie so the whole server sleeps :/ and I don't know how to use $tick and schedule delay task. Someone please help! thanks PHP: <?phpnamespace ipe\lipe;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\plugin\Plugin;use pocketmine\Server;use pocketmine\Player;use pocketmine\utils\Config;class Main extends PluginBase implements Listener{ public function execute(CommandSender $sender, $commandLabel, array $args) { if($sender instanceof Player) { if(isset($args[0])) { switch($args[0]) { case "serverinfo": $sender->addTitle("*****", "*****", 45, 55, 45); sleep(3); $sender->addTitle("*****", "*****", 45, 55, 45); sleep(3); $sender->addTitle("§eManaged by:", "*****", 45, 55, 45); sleep(3); $sender->addTitle("§eRead the Rules @", "*****", 45, 55, 45); sleep(3); $sender->addTitle("§eSend a support ticket @", "*****", 45, 55, 45); sleep(3); $sender->addTitle("§ePurcahse a Rank @", "*****", 45, 55, 45); sleep(3); $sender->addTitle("§eVote for us @", "*****", 45, 55, 45); sleep(3); $sender->addTitle("§eFor More info Visit:", "*****", 45, 55, 45); } } } }
That won't fix your problem. Learn what sleep() does, it pauses the whole main thread, so nothing will happen on your server for 21 seconds after that command is run. You need to use PluginTasks
You can use this: PHP: /* * Main.php * @var CommandSender $sender * @var array $sender * @var int $secs */$secs = 3; // time to wait in between every title message$messages = array( "Message 1", "Message 2", "Message 3", "Message 4" );SendTitles::$times = 0; // reset the counter$this->getServer()->getScheduler()->scheduleRepeatingTask(new SendTitles($this, $sender, $messages), $secs * 20);/* * SendTitles.php * @var static $times */public function onRun(int $tick) { if(self::$times >= count($this->messages)) { // do this until the end of the 'messages' array is reached Server::getInstance()->getScheduler()->cancelTask($this->getTaskId()); // cancel task } else { $this->sender->addTitle($this->messages[self::$times]); self::$times = self::$times + 1; } }
If you used a few seconds of your time using the search bar you could've saved the time everyone else spent replying to this thread. https://forums.pmmp.io/threads/creating-a-timer-with-tasks.136/