Solved Error: Call to undefined method pocketmine\Server::getScheduler()

Discussion in 'Development' started by MSG100PM, Jul 8, 2018.

  1. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    775
    GitHub:
    dktapps
    jasonwynn10 and HimbeersaftLP like this.
  3. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Still confused.
    What should I add or delete?
     
  4. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
  5. Sergey Dertan

    Sergey Dertan Silverfish

    Messages:
    19
    just replace $Server->getScheduler() with $pluginMainClass->getScheduler().
    For example, there u need replace
    PHP:
    $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\SaveTask($this), $i *= 1200$i); 
    with
    PHP:
    $this->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\SaveTask($this), $i *= 1200$i);
     
    MSG100PM likes this.
  6. corytortoise

    corytortoise Skeleton

    Messages:
    826
    GitHub:
    corytortoise
    The tasks themselves also need to no longer extend PluginTask, because that class no longer exists. I believe all you have to do is implement the Task interface now, and don't parent::__construct in your Task's class.
     
    MSG100PM likes this.
  7. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Thanks it worked!
     
  8. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Hello, it gave me this error:
    Code:
    [20:25:20] [Server thread/CRITICAL]: [Server] Could not execute task [email protected] C:\Users\\Desktop\PocketMine-MP\plugins\111-Server_v0-585af\src\Server\Server.php00000225916C0A0B: Undefined variable: plugin
    [20:25:20] [Server thread/CRITICAL]: ErrorException: "Undefined variable: plugin" (EXCEPTION) in "111-Server_v0-585af/src/Server/Server" at line 57
    [20:25:20] [Server thread/DEBUG]: #0 111-Server_v0-585af/src/Server/Server(57): pocketmine\utils\Utils::errorExceptionHandler(integer 8, string Undefined variable: plugin, string C:\Users\\Desktop\PocketMine-MP\plugins\111-Server_v0-585af\src\Server\Server.php, integer 57, array Array())
    [20:25:20] [Server thread/DEBUG]: #1 src/pocketmine/scheduler/TaskHandler(163): [email protected] C:\Users\\Desktop\PocketMine-MP\plugins\111-Server_v0-585af\src\Server\Server.php00000225916C0A0B->onRun(integer 276)
    [20:25:20] [Server thread/DEBUG]: #2 src/pocketmine/scheduler/TaskScheduler(203): pocketmine\scheduler\TaskHandler->run(integer 276)
    [20:25:20] [Server thread/DEBUG]: #3 src/pocketmine/plugin/PluginManager(718): pocketmine\scheduler\TaskScheduler->mainThreadHeartbeat(integer 276)
    [20:25:20] [Server thread/DEBUG]: #4 src/pocketmine/Server(2504): pocketmine\plugin\PluginManager->tickSchedulers(integer 276)
    [20:25:20] [Server thread/DEBUG]: #5 src/pocketmine/Server(2255): pocketmine\Server->tick()
    [20:25:20] [Server thread/DEBUG]: #6 src/pocketmine/Server(2129): pocketmine\Server->tickProcessor()
    [20:25:20] [Server thread/DEBUG]: #7 src/pocketmine/Server(1710): pocketmine\Server->start()
    [20:25:20] [Server thread/DEBUG]: #8 src/pocketmine/PocketMine(237): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\\Desktop\PocketMine-MP\, string C:\Users\\Desktop\PocketMine-MP\plugins\)
    [20:25:20] [Server thread/DEBUG]: #9 C:/Users//Desktop/PocketMine-MP/PocketMine-MP.phar(1): require(string phar://C:/Users//Desktop/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    When trying to update this plugin:
    PHP:
    <?php

    namespace Server;

    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\utils\Config;

    class 
    Server extends PluginBase implements Listener{

        public 
    $config;

        public function 
    onEnable(){
            @
    mkdir($this->getDataFolder());
            
    $this->config = new Config($this->getDataFolder() . "setting.yml"Config::YAML, [
                
    "message" => "§l§cMega§eCraft§aPE§f: §r§7Thank you for playing on our server, play games, invite your friends, We are Currently in BETA!\n\n §aYou are already logged in by your xBox live account!",
                
    "tip" => "",
                
    "title" => "§bMega§4PE",
                
    "subtitle" => "§dAdvanced §3KitPvP §aNetwork",
                
    "actionbar" => "",
                
    "fadein" => 30,
                
    "stay" => 80,
                
    "fadeout" => 30
            
    ]);

            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onDisable(){

        }

        public function 
    onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            if((
    $message $this->config->get("message")) !== ""){
                
    $player->sendMessage($this->replaceParameters($player$message));
            }
            if((
    $popup $this->config->get("popup")) !== ""){
                
    $player->sendPopup($this->replaceParameters($player$popup));
            }
            if((
    $tip $this->config->get("tip")) !== ""){
                
    $player->sendTip($this->replaceParameters($player$tip));
            }
            if(
    $this->config->get("title") !== ""){
                
    $this->getScheduler()->scheduleDelayedTask(new class($this$event->getPlayer()) extends Task{
                    public 
    $player;

                    public function 
    __construct(Server $pluginPlayer $player){
                        
    $this->player $player;
                    }

                    public function 
    onRun($currentTick){
                        
    $player $this->player;
                        
    $title $plugin->replaceParameters($player$config->get("title"));
                        
    $subtitle $plugin->replaceParameters($player$config->get("subtitle"));
                        
    $actionbar $plugin->replaceParameters($player$config->get("actionbar"));

                        
    $fadein $config->get("fadein");
                        
    $stay $config->get("stay");
                        
    $fadeout $config->get("fadeout");
                        switch(
    $this->owner->getServer()->getName()){
                            case 
    "Tesseract":
                                
    $player->sendTitle($title$subtitle$fadein$fadeout$stay);

                            default: 
    // PocketMine-MP
                                
    $player->addTitle($title$subtitle$fadein$stay$fadeout);
                                
    $player->addActionBarMessage($actionbar);
                                
    //$this->player->addTitle($title, $subtitle, $fadein, $stay, $fadeout);
                                
    break;
                        }
                    }
                }, 
    30);
            }
        }

        public function 
    replaceParameters(Player $player$string){
            return 
    str_replace([
                
    "{NAME}",
                
    "{MOTD}"
            
    ], [
                
    $player->getName(),
                
    $this->getServer()->getMotd()
            ], 
    $string);
        }
    }
     
  9. Sergey Dertan

    Sergey Dertan Silverfish

    Messages:
    19
    Add $this->plugin=$plugin to u`r anonymous class constructor, and add $plugin=$this->plugin to onRun function
     
    MSG100PM likes this.
  10. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    hmm, I'm not sure if I get it, what does the full code look like?
     
  11. Sergey Dertan

    Sergey Dertan Silverfish

    Messages:
    19
    PHP:
    <?php

    namespace Server;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\utils\Config;

    class 
    Server extends PluginBase implements Listener
    {

        public 
    $config;

        public function 
    onEnable()
        {
            @
    mkdir($this->getDataFolder());
            
    $this->config = new Config($this->getDataFolder() . "setting.yml"Config::YAML, [
                
    "message"   => "§l§cMega§eCraft§aPE§f: §r§7Thank you for playing on our server, play games, invite your friends, We are Currently in BETA!\n\n §aYou are already logged in by your xBox live account!",
                
    "tip"       => "",
                
    "title"     => "§bMega§4PE",
                
    "subtitle"  => "§dAdvanced §3KitPvP §aNetwork",
                
    "actionbar" => "",
                
    "fadein"    => 30,
                
    "stay"      => 80,
                
    "fadeout"   => 30
            
    ]);

            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onDisable()
        {

        }

        public function 
    onJoin(PlayerJoinEvent $event)
        {
            
    $player $event->getPlayer();
            if ((
    $message $this->config->get("message")) !== "") {
                
    $player->sendMessage($this->replaceParameters($player$message));
            }
            if ((
    $popup $this->config->get("popup")) !== "") {
                
    $player->sendPopup($this->replaceParameters($player$popup));
            }
            if ((
    $tip $this->config->get("tip")) !== "") {
                
    $player->sendTip($this->replaceParameters($player$tip));
            }
            if (
    $this->config->get("title") !== "") {
                
    $this->getScheduler()->scheduleDelayedTask(new class($this$event->getPlayer()) extends Task
                
    {
                    public 
    $player;
                    public 
    $plugin;

                    public function 
    __construct(Server $pluginPlayer $player)
                    {
                        
    $this->player $player;
                        
    $this->plugin $plugin;
                    }

                    public function 
    onRun($currentTick)
                    {
                        
    $player $this->player;
                        
    $plugin $this->plugin;
                        
    $config $plugin->config;
                        
    $title $plugin->replaceParameters($player$config->get("title"));
                        
    $subtitle $plugin->replaceParameters($player$config->get("subtitle"));
                        
    $actionbar $plugin->replaceParameters($player$config->get("actionbar"));

                        
    $fadein $config->get("fadein");
                        
    $stay $config->get("stay");
                        
    $fadeout $config->get("fadeout");
                        switch (
    $plugin->getServer()->getName()) {
                            case 
    "Tesseract":
                                
    $player->sendTitle($title$subtitle$fadein$fadeout$stay);

                            default: 
    // PocketMine-MP
                                
    $player->addTitle($title$subtitle$fadein$stay$fadeout);
                                
    $player->addActionBarMessage($actionbar);
                                
    //$this->player->addTitle($title, $subtitle, $fadein, $stay, $fadeout);
                                
    break;
                        }
                    }
                }, 
    30);
            }
        }

        public function 
    replaceParameters(Player $player$string)
        {
            return 
    str_replace([
                
    "{NAME}",
                
    "{MOTD}"
            
    ], [
                
    $player->getName(),
                
    $this->getServer()->getMotd()
            ], 
    $string);
        }
    }
     
    MSG100PM likes this.
  12. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Thank you all, but I just have One last error with CombatLogger, plugin : (https://github.com/JackNoordhuis/PocketMine-Plugins/tree/master/CombatLogger)

    I fixed the Server scheduler thing and the Tasks, but this came up:

    The error:
    PHP:
    [17:22:43] [Server thread/CRITICAL]: [CombatLoggerCould not execute task jacknoordhuis\combatlogger\TaggedHeartbeatTaskCall to undefined method jacknoordhuis\combatlogger\TaggedHeartbeatTask::getOwner()
    [
    17:22:43] [Server thread/CRITICAL]: Error"Call to undefined method jacknoordhuis\combatlogger\TaggedHeartbeatTask::getOwner()" (EXCEPTIONin "CombatLogger-master/src/jacknoordhuis/combatlogger/TaggedHeartbeatTask" at line 30
    [17:22:43] [Server thread/DEBUG]: #0 CombatLogger-master/src/jacknoordhuis/combatlogger/TaggedHeartbeatTask(34): jacknoordhuis\combatlogger\TaggedHeartbeatTask->getPlugin()
    [17:22:43] [Server thread/DEBUG]: #1 src/pocketmine/scheduler/TaskHandler(163): jacknoordhuis\combatlogger\TaggedHeartbeatTask->onRun(integer 1)
    [17:22:43] [Server thread/DEBUG]: #2 src/pocketmine/scheduler/TaskScheduler(203): pocketmine\scheduler\TaskHandler->run(integer 1)
    [17:22:43] [Server thread/DEBUG]: #3 src/pocketmine/plugin/PluginManager(714): pocketmine\scheduler\TaskScheduler->mainThreadHeartbeat(integer 1)
    [17:22:43] [Server thread/DEBUG]: #4 src/pocketmine/Server(2504): pocketmine\plugin\PluginManager->tickSchedulers(integer 1)
    [17:22:43] [Server thread/DEBUG]: #5 src/pocketmine/Server(2255): pocketmine\Server->tick()
    [17:22:43] [Server thread/DEBUG]: #6 src/pocketmine/Server(2129): pocketmine\Server->tickProcessor()
    [17:22:43] [Server thread/DEBUG]: #7 src/pocketmine/Server(1710): pocketmine\Server->start()
    [17:22:43] [Server thread/DEBUG]: #8 src/pocketmine/PocketMine(237): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\\Desktop\PocketMine-MP\, string C:\Users\\Desktop\PocketMine-MP\plugins\)
    [17:22:43] [Server thread/DEBUG]: #9 C:/Users//Desktop/PocketMine-MP/PocketMine-MP.phar(1): require(string phar://C:/Users//Desktop/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
     
  13. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    My edits:
    PHP:
    <?php

    /**
     * CombatLogger plugin for PocketMine-MP
     * Copyright (C) 2017 JackNoordhuis
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as published by
     * the Free Software Foundation, either version 2 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     */

    namespace jacknoordhuis\combatlogger;

    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\scheduler\Task;

    class 
    TaggedHeartbeatTask extends Task {

        
    /**
         * @return CombatLogger|Plugin
         */
        
    public function getPlugin() {
            return 
    $this->getOwner();
        }

        public function 
    onRun(int $currentTick) {
            
    $plugin $this->getPlugin();
            foreach(
    $plugin->taggedPlayers as $name => $time) {
                
    $time--;
                if(
    $time <= 0) {
                    
    $plugin->setTagged($namefalse);
                    
    $player $plugin->getServer()->getPlayerExact($name);
                    if(
    $player instanceof Player$player->sendMessage($plugin->getMessageManager()->getMessage("player-tagged-timeout"));
                    return;
                }
                
    $plugin->taggedPlayers[$name]--;
            }
        }

    }
     
  14. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Need help updating, thanks! :)
     
  15. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    What is your problem?
     
  16. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    CombatLogger plugin updating, above.
     
  17. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    PHP:
    PHP:
    <?php

    /**
     * CombatLogger plugin for PocketMine-MP
     * Copyright (C) 2017 JackNoordhuis
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as published by
     * the Free Software Foundation, either version 2 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     */

    namespace jacknoordhuis\combatlogger;

    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\scheduler\Task;

    class 
    TaggedHeartbeatTask extends Task {

       public function 
    __construct(CombatLogger $main){
       
    $this->main $main;
    }

        public function 
    onRun(int $currentTick) {
            
    $plugin $this->main;
            foreach(
    $plugin->taggedPlayers as $name => $time) {
                
    $time--;
                if(
    $time <= 0) {
                    
    $plugin->setTagged($namefalse);
                    
    $player $plugin->getServer()->getPlayerExact($name);
                    if(
    $player instanceof Player$player->sendMessage($plugin->getMessageManager()->getMessage("player-tagged-timeout"));
                    return;
                }
                
    $plugin->taggedPlayers[$name]--;
            }
        }

    }
     
    MSG100PM likes this.
  18. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Thank you, @KHAV :)
     
    KHAV likes this.
  19. Krishna vishwakarma

    Krishna vishwakarma Creeper

    Messages:
    3
    "Call to undefined

    method pocketmine\item Item::get()" (EXCEPTION) in "plugins/ SkyBlock-pm4.phar/src/room 17/SkyBlock/utils/Utils" at line 27
     
  20. Krishna vishwakarma

    Krishna vishwakarma Creeper

    Messages:
    3
    What I do for that
     

Share This Page

  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.