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

Call to unfedined method ::getOwner()

Discussion in 'Development' started by CupidonSauce173, Jul 25, 2018.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hi, so I was updating CombatLogger of 3.0.0-ALPHA12 to 3.0.01 and I found that issue, getOwner() seem to be a undefined method, here is the code of the Task
    PHP:
    use pocketmine\Player;
    use 
    pocketmine\scheduler\Task;

    class 
    TaggedHeartbeatTask extends Task {

        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]--;
            }
        }

    }
    I never really used getOwner and I tried to find it on pmmp but never found it..If someone can help.
     
  2. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    When you hit someone, it will cancel the blocked commands in settings and send the message that you can't use commands while you are in combat but the plugin doesn't return, so the player stay in combat mode forever
     
  3. Aenteritas

    Aenteritas Silverfish

    Messages:
    22
    PHP:
    public function onRun(int $currentTick) :void {
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    this doesn't make any sense
     
  5. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    It was working well on 3.0.0-ALPHA12
     
  6. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    It doesn't hurt.

    getOwner() was part of PluginTask, which was removed in the scheduler nuke pr. If you wish to use your plugin instance pass it over to the constructor.
    Here's an example:
    https://github.com/SalmonDE/TopVote...DE/TopVoter/Tasks/UpdateVotesTask.php#L15-L16
     
    xXNiceAssassinlo YT likes this.
  7. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
        public function __construct(ClassYouSchedule $plugin){
            
    $this->plugin $plugin;
        }

        public function 
    getOwner() : ClassYouSchedule{
            return 
    $this->plugin;
        }
     
  9. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    It's working with that too :
    PHP:
    class TaggedHeartbeatTask extends Task {

        private 
    $plugin;
        
        public function 
    __construct(CombatLogger $plugin) {
            
    $this->plugin $plugin;
            return;
        }


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

    }
     
  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.