Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Async getPluginManager() on null

Comments in 'Plugin Development' started by Samueljh1H8sLag, Aug 7, 2015.

  1. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Hi, sometimes i get a fatal error when running an asynctask. Its the getPluginManager() on null error.

    here is the asynctask code:

    PHP:

    <?php

    ###
    # SamCraft SkyWars - Core Plugin | Sql Task
    ###

    namespace Samueljh1\Samcraft\SkyWars\LeaderboardSystem;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\scheduler\ServerScheduler;
    use 
    pocketmine\scheduler\AsyncTask;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Server;

    private 
    $leaderboard;

    class 
    getdata extends AsyncTask{

         public function 
    onRun(){

              
    //async code not related to error

         
    }

         public function 
    onCompletion(Server $server){

              
    $server->getPluginManager()->getPlugin("SkyWars-Leaderboard")->processData($this->leaderboard);

         }

    }

    Any ideas/replacements for the getPluginManager() line?

    thanks :D

    @PEMapModder u will probably know xD
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yea give PluginManager class instead of Server
  3. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    so pass that through the onCompletion params?
  4. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    PHP:
    [20:45:49] [Server thread/NOTICE]: RuntimeException"Declaration of Samueljh1\Samcraft\SkyWars\LeaderboardSystem\getdata::onCompletion() should be compatible with pocketmine\scheduler\AsyncTask::onCompletion(pocketmine\Server $server)" (E_STRICTin "/SkyWars-Leaderboard/src/Samueljh1/Samcraft/SkyWars/LeaderboardSystem/getdata" at line 37
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yes from where are you calling it?
  6. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
      public function onCompletion(PluginManager $pm){
    $pm->getPlugin("SkyWars-Leaderboard")->processData($this->leaderboard);
     }
    when you call it:
    PHP:
    $this->getdata->onCompletion($this->getPluginManager());
  8. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    ? i just showed you the error if you do that
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ouh i'm sorry did'nt see this part:
    pocketmine\scheduler\AsyncTask::eek:nCompletion ( Server $server)
    :)
    Dont do what i said before!
    Idk why it's letting through $server if it is an instanceof Server but saying on null :D
    Try checking before this action
    PHP:
    public function onCompletion(Server $server){
     (
    $server != null $server->getPluginManager()->getPlugin("SkyWars-Leaderboard")->processData($this->leaderboard)  : $this->getLogger()->alert('[ERROR]'));
    )
    }
  10. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    yes but the server should always work. something weird is happening and that means that sometimes the asynctask won't complete properly because i can't call the finishing function
  11. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    nevermind, i just use main::getInstance($server)->func()
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP bugs.
  13. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Wat, the cause of da err?
    PEMapModder and Legoboy0215 like this.

Share This Page

Advertisement