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

Scheduler pls help me

Discussion in 'Development' started by GrieferHax, May 10, 2021.

  1. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    Hello but i found every things about the scheduler from old api can ever make an example scheduler code why than i know how to use but every was i found in the Last 2 days dont work and is really Bad than you Lost the fun on coding pls help me
     
    Last edited: May 10, 2021
  2. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    In old APIs, task schedulers are share between plugin, so it can be get from the Server instance ($this->getServer()->getScheduler()). But in API 3, task schedulers are per plugin, so you have to directly get from the plugin instance instead of the Server instance ($this->getScheduler()).
     
    Primus and minijaham like this.
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    How did you even understand what he said
     
    Primus likes this.
  4. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    PocketMine Thonker logic :thinkies:
     
    Primus likes this.
  5. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    Ok but im never bevor working with scheduler but i dont know how to use this and on the api site i can see in wat i can get an what i musst implementiert but not war function i muss call of something dor bukkit you can see that all on the learn bukkit api site
     
  6. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    @EndermannbugZJFC
    My Main Class:
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    ghax\task;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\scheduler\Task as PluginTask;
    use 
    ghax\task\RTask;

    class 
    Main extends PluginBase{
       
        public function 
    onEnable(){
            
    $this->getScheduler()->schedulerReapeatingTask(new RTask($this),20);
        }

    }
    My Task Class:
    PHP:
    <?php

    namespace ghax\task;

    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    ghax\task\Main;

    class 
    RTask extends Task{
        private 
    $plugin;
       
        public function 
    __construct(Main $plugin){
            
    $plugin $this->plugin();
        }
       
        public function 
    onRun($currentTick){
            
    $this->plugin->getServer()->broadcastMessage("test");
        }
    }
     
  7. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    scheduleRepeatingTask(), you typed extra r. Here is PocketMine not Bukkit, you are suppose to follow the PocketMine documents and tutorials.
     
    minijaham likes this.
  8. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    I have dollow a titorial that is the code but dont work an i can php and i lok on the api site but every what i search over scheduler pocketmine dont work and i tell kann every make pls example code that i know how ist work than i can learn it
     
  9. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    Did you read what I said? You typed an extra r in schedulerRepeatingTask()
     
    minijaham likes this.
  10. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    [Server thread/CRITICAL]: Error: "Call to undefined method ghax\task\RTask::plugin()" (EXCEPTION) in "plugins/task/src/ghax/task/RTask" at line 16
     
  11. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    Fixed code:
    PHP:
    <?php

    namespace ghax\task;

    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    ghax\task\Main;

    class 
    RTask extends Task{
        private 
    $plugin;
     
        public function 
    __construct(Main $plugin){
            
    $this->plugin $plugin;
        }
     
        public function 
    onRun($currentTick){
            
    $this->plugin->getServer()->broadcastMessage("test");
        }
    }
    Use code box since emojis will fuck up your errors and codes
     
    minijaham likes this.
  12. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    You did it wrong. It's not
    PHP:
    public function __construct(Main $plugin){
            
    $plugin $this->plugin();
        }
    it's
    PHP:
    public function __construct(Main $plugin){
            
    $this->plugin $plugin;
        }
     
  13. GrieferHax

    GrieferHax Silverfish

    Messages:
    19
    Now its working Thank You :D
     
    Last edited: May 12, 2021
  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.