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

Solved problem with query!!

Discussion in 'Development' started by 7awariGamer, Apr 21, 2019.

  1. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    this is the problem :
    Code:
    [21:26:34] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\Server::getScheduler()" (EXCEPTION) in "plugins/UP-stockpe/src/NetworkQuery/Network" at line 80
    and there is the code ;
    Code:
    public function updateQueryData()
        {
           //line 80 $this->server->getScheduler()->scheduleAsyncTask(new AsyncQueryTask($this->servers));
            $this->update();
        }
        public function getQueries()
        {
            return $this->queryData;
        }
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    what is inside
    AsyncQueryTask
     
  3. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    PHP:
    namespace NetworkQuery\tasks;

    use 
    NetworkQuery\{FakePlayerNetwork};
    use 
    pocketmine\scheduler\AsyncTask;
    use 
    pocketmine\Server;

    class 
    AsyncQueryTask extends AsyncTask {

        private 
    $serverdata;

        public function 
    __construct(array $serverdata)
        {
            
    $this->serverdata = (array) $serverdata;
        }

        public function 
    onRun()
        {
            
    $opt = [];
            foreach (
    $this->serverdata as $server) {
                
    $data = [
                    
    $server[0],
                    
    $server[1]
                ];
                
    $json json_decode(file_get_contents(str_replace('{DATA}'implode(':'$server), Network::MC_API)));
                if (
    $json->status == false) {
                    
    $data[2] = [
                        
    "online" => 0,
                        
    "players" => []
                    ];
                } else {
                    
    $players $json->list ?? [];
                    if (!empty(
    $players)) {
                        foreach (
    $players as $k => $v) {
                            
    $players[$k] = new FakePlayer($v);
                        }
                    }
                    
    $data[2] = [
                        
    "online" => $json->players->online,
                        
    "players" => $players
                    
    ];
                }
                
    $opt[] = $data;
            }
            
    $this->setResult($opt);
        }

        public function 
    onCompletion(Server $server)
        {
            
    $network $server->getPluginManager()->getPlugin('NetworkQuery')->getNetwork();
            foreach (
    $this->getResult() as $data) {
                
    $network->setQueryData(...$data);
            }
            
    $network->update();
        }
    }
     
  4. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    there has been new API on scheduling async
    PHP:
    $this->getServer()->getAsyncPool()->submitTask();
     
  5. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    thx
     
  6. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    doesnt works
     
  7. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    What doesn't
     
  8. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    I puted the new code but it doesn't works !
    The console shows me the same error
     
  9. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    PHP:
    $this->server->getAsyncPool()->submitTask(new AsyncQueryTask($this->servers));
    I fixed it , thx lol
     
  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.