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

__Construct Failure

Discussion in 'Plugin Help' started by timistwild, Mar 4, 2021.

  1. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Hi! I want to access the main because i want to create my config in the Eventlistener.
    But with this code:
    PHP:
    public function __construct(Main $plugin$playerName){
            
    $this->plugin $plugin;//This is line 31
        
    }
    And also with this code:
    Code:
    public function __construct(Main $plugin){
            $this->plugin = $plugin;//This is line 31
        }
    This failure comes:
    Code:
     [Server thread/CRITICAL]: ArgumentCountError: "Too few arguments to function Tim\SoupFFA\listener\EventListener::__construct(), 0 passed in C:\Users\beisp\Desktop\neuer server\plugins\SoupFFA\src\Tim\SoupFFA\Main.php on line 24 and exactly 2 expected" (EXCEPTION) in "plugins/SoupFFA/src/Tim/SoupFFA/listener/EventListener" at line 31
    [17:13:19] [Server thread/CRITICAL]: #0 plugins/SoupFFA/src/Tim/SoupFFA/Main(24): Tim\SoupFFA\listener\EventListener->__construct()
    [17:13:19] [Server thread/CRITICAL]: #1 pmsrc/src/pocketmine/plugin/PluginBase(116): Tim\SoupFFA\Main->onEnable()
    [17:13:19] [Server thread/CRITICAL]: #2 pmsrc/src/pocketmine/plugin/PluginManager(552): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    [17:13:19] [Server thread/CRITICAL]: #3 pmsrc/src/pocketmine/Server(1786): pocketmine\plugin\PluginManager->enablePlugin(object Tim\SoupFFA\Main)
    [17:13:19] [Server thread/CRITICAL]: #4 pmsrc/src/pocketmine/Server(1772): pocketmine\Server->enablePlugin(object Tim\SoupFFA\Main)
    [17:13:19] [Server thread/CRITICAL]: #5 pmsrc/src/pocketmine/Server(1585): pocketmine\Server->enablePlugins(integer 1)
    [17:13:19] [Server thread/CRITICAL]: #6 pmsrc/src/pocketmine/PocketMine(291): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[36] C:\Users\beisp\Desktop\neuer server\, string[44] C:\Users\beisp\Desktop\neuer server\plugins\)
    [17:13:19] [Server thread/CRITICAL]: #7 pmsrc/src/pocketmine/PocketMine(321): pocketmine\server()
    [17:13:19] [Server thread/CRITICAL]: #8 pmsrc(11): require(string[91] phar://C:/Users/beisp/Desktop/neuer server/PocketMine-MP.phar/src/pocketmine/Poc)
    Anyone know what this mean?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    the error is where this piece of code is located "new EventListener()". Check Main on line 24
     
    timistwild likes this.
  3. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Mhm weird. This is the line
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new EventListener(), $this);
     
  4. mmm545

    mmm545 Baby Zombie

    Messages:
    152
    GitHub:
    mmm545
    exactly what the error says
    Code:
    Too few arguments to function
    
    you didn't pass any arguments to the EventListener's constructor, it needs one argument, which is the main instance
    to fix it, pass the main instance to EventListener
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
    Edit: @Primus hah, too slow kek
     
    Last edited: Mar 4, 2021
    ethaniccc, timistwild and Primus like this.
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    Not at all! If you look at __contruct method signature, then you'll notice that 1st parameter is object of instance Main, however you pass exactly none.
     
    timistwild and mmm545 like this.
  6. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Oh yea i forgot that one. Thank you guys!
     
  7. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Now my task isnt found anymore :/ Is there a way to bypass this problem?
    PHP:
    public function onEnable()
        {
           
            
    #Register Listener
            
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
            
    #Register Database
            
    @mkdir($this->getDataFolder() . "Database/");
            
    #Register Task
            
    $this->getScheduler()->scheduleRepeatingTask(new ScoreboardTask($this), 20);

        }
     
  8. Sir E of Cali

    Sir E of Cali Creeper

    Messages:
    5
    GitHub:
    xjustjqy
    You'd have to give more information than just the onEnable function. Where is the task file located?
     
    Primus likes this.
  9. timistwild

    timistwild Spider Jockey

    Messages:
    33
    This is the location:
    upload_2021-3-5_11-51-13.png
    And this is the error:
    PHP:
     [Server thread/CRITICAL]: Error"Class 'Tim\SoupFFA\ScoreboardTask' not found" (EXCEPTIONin "plugins/SoupFFA/src/Tim/SoupFFA/Main" at line 30
    [10:48:34] [Server thread/CRITICAL]: #0 pmsrc/src/pocketmine/plugin/PluginBase(116): Tim\SoupFFA\Main->onEnable()
    [10:48:34] [Server thread/CRITICAL]: #1 pmsrc/src/pocketmine/plugin/PluginManager(552): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    [10:48:34] [Server thread/CRITICAL]: #2 pmsrc/src/pocketmine/Server(1786): pocketmine\plugin\PluginManager->enablePlugin(object Tim\SoupFFA\Main)
    [10:48:34] [Server thread/CRITICAL]: #3 pmsrc/src/pocketmine/Server(1772): pocketmine\Server->enablePlugin(object Tim\SoupFFA\Main)
    [10:48:34] [Server thread/CRITICAL]: #4 pmsrc/src/pocketmine/Server(1585): pocketmine\Server->enablePlugins(integer 1)
    [10:48:34] [Server thread/CRITICAL]: #5 pmsrc/src/pocketmine/PocketMine(291): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[36] C:\Users\beisp\Desktop\neuer server\, string[44] C:\Users\beisp\Desktop\neuer server\plugins\)
    [10:48:34] [Server thread/CRITICAL]: #6 pmsrc/src/pocketmine/PocketMine(321): pocketmine\server()
    [10:48:34] [Server thread/CRITICAL]: #7 pmsrc(11): require(string[91] phar://C:/Users/beisp/Desktop/neuer server/PocketMine-MP.phar/src/pocketmine/Poc)
     

    Attached Files:

  10. Primus

    Primus Zombie Pigman

    Messages:
    749
    Check if ScoreboardTask.php has declared namespace correctly.
     
    timistwild likes this.
  11. Sir E of Cali

    Sir E of Cali Creeper

    Messages:
    5
    GitHub:
    xjustjqy
    That, or remove this if you have it:
    PHP:
    use Tim\SoupFFA\ScoreboardTask;
    Considering it’s in the same directory (with the same namespace) it unnecessary to include it.
     
    Primus and timistwild like this.
  12. timistwild

    timistwild Spider Jockey

    Messages:
    33
    Oh yeah one use was use namespace SoupFFA....
    Sorry for the problems and thank you :)
     
    mmm545 and Primus like this.
  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.