1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Task

Discussion in 'Development' started by JarguarLoveMC, Aug 28, 2019.

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    Console output: Server thread/CRITICAL Error: "Call to undefined method pocketmine\Server::scheduleDelayedTask()

    Main.php
    PHP:
    <?php

    namespace DelayedCommands;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;

    class 
    Main extends PluginBase implements Listener{
     
      public function 
    onEnable(){
          
    $this->getServer()->getPluginManager()->registerEvents($this$this);
          
    $this->getServer()->scheduleDelayedTask(new SendCommandTask($this), 400);
          
          }
      }
    SendCommandTask.php
    PHP:
    <?php

    namespace DelayedCommands;

    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    SendCommandTask extends PluginTask{
        
        public function 
    onRun(int $currentTick){

            
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "say hi");
        }
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    $this->getScheduler()->scheduleDelayedTask(new SendCommandTask(), 400);
    Change PluginTask to Task
    Change $this->getServer() inside onRun to Server::getInstance()
     
    HimbeersaftLP and JarguarLoveMC like this.
  3. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    Tysm you are my life saver
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.