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

Cannot call constructor

Discussion in 'Plugin Help' started by minijaham, Apr 27, 2020.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Server thread/CRITICAL Error: "Cannot call constructor" (EXCEPTION) in "plugins/DropParty/src/dropparty/task/DropPartyTask" at line 14

    Uhh how do I make the "CODE:" and "PHP:"?
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    <?php

    namespace dropparty\task;

    use pocketmine\scheduler\Task;
    use dropparty\DropParty;
    use pocketmine\item\Item;
    use pocketmine\utils\Config;
    use pocketmine\math\Vector3;

    class DropPartyTask extends Task {

    public function __construct(DropParty $plugin) {
    parent::__construct($plugin);
    $this->$this->getPlugin();
    }

    public function getPlugin() {
    return $this->plugin;
    }

    public function onRun(int $currentTick) {
    $msg = str_replace("{time}", $this->getPlugin()->time, $this->getPlugin()->config()["Message.Countdown"]);
    if($this->getPlugin()->time > 0) {
    $this->getPlugin()->getServer()->broadcastMessage($msg);
    }

    if($this->getPlugin()->time == 0) {
    $this->getPlugin()->getServer()->broadcastMessage($this->getPlugin()->config()["Message.Started"]);
    $this->getPlugin()->status = "enabled";
    }

    $this->getPlugin()->time = $this->getPlugin()->time - 1;

    }

    }
     
  3. anirudh246

    anirudh246 Spider Jockey

    Messages:
    29
    Hey! I’m not sure about line 14, but why did you write the pseudo variable twice?

    $this->$this->getPlugin();

    As far as I’m aware things don’t work like that. Change the variable name, and change the first object operator to an equals sign.
     
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Thanks for the reply! I fixed the issue and it's now working good!
     
  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.