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

Async Scoreboard

Discussion in 'General discussion' started by Ectary Network, Sep 12, 2020.

  1. Ectary Network

    Ectary Network Creeper

    Messages:
    2
    GitHub:
    xeww
    ok so basically i wanted to make a scoreboard in asynctask, it works perfectly but for some reason everytime it complete there is a 1sec freeze on my server.
    I'm starting my asynctask with a normal repeating task which repeat every 50 ticks.
    I tried to:
    - Look at my ram (fine)
    - Look at my cpu (fine)
    - Look at my cpu swap (fine)
    - I tried to var_dump a microtime (fine)
    - I did a timings and everything is fine too
    So i'm really confused.
    Here is my async task code if you can help me, thanks! (My english is pretty bad sorry.)
    PHP:
        public function onRun()
        {
            
    $remove = new RemoveObjectivePacket();
            
    $remove->objectiveName "test";

            
    $title = new SetDisplayObjectivePacket();
            
    $title->displaySlot "sidebar";
            
    $title->objectiveName "test";
            
    $title->displayName "§r   §bEctary§r §7(EU Practice)   §r";
            
    $title->criteriaName "dummy";
            
    $title->sortOrder 0;

            
    $entrie = new ScorePacketEntry();
            
    $entrie->objectiveName "test";
            
    $entrie->type ScorePacketEntry::TYPE_FAKE_PLAYER;
            
    $entrie->customName "§7--------------------";
            
    $entrie->score 1;
            
    $entrie->scoreboardId 1;
            
    $line1 = new SetScorePacket();
            
    $line1->type 0;
            
    $line1->entries[] = $entrie;

            
    $entrie = new ScorePacketEntry();
            
    $entrie->objectiveName "test";
            
    $entrie->type ScorePacketEntry::TYPE_FAKE_PLAYER;
            
    $entrie->customName "§fQueued: §b{$this->queued}";
            
    $entrie->score 2;
            
    $entrie->scoreboardId 2;
            
    $line2 = new SetScorePacket();
            
    $line2->type 0;
            
    $line2->entries[] = $entrie;

            
    $entrie = new ScorePacketEntry();
            
    $entrie->objectiveName "test";
            
    $entrie->type ScorePacketEntry::TYPE_FAKE_PLAYER;
            
    $entrie->customName "§fDivision: §b{$this->division}";
            
    $entrie->score 3;
            
    $entrie->scoreboardId 3;
            
    $line3 = new SetScorePacket();
            
    $line3->type 0;
            
    $line3->entries[] = $entrie;

            
    $entrie = new ScorePacketEntry();
            
    $entrie->objectiveName "test";
            
    $entrie->type ScorePacketEntry::TYPE_FAKE_PLAYER;
            
    $entrie->customName "§r";
            
    $entrie->score 4;
            
    $entrie->scoreboardId 4;
            
    $line4 = new SetScorePacket();
            
    $line4->type 0;
            
    $line4->entries[] = $entrie;

            
    $entrie = new ScorePacketEntry();
            
    $entrie->objectiveName "test";
            
    $entrie->type ScorePacketEntry::TYPE_FAKE_PLAYER;
            
    $entrie->customName "§bectary.club";
            
    $entrie->score 5;
            
    $entrie->scoreboardId 5;
            
    $line5 = new SetScorePacket();
            
    $line5->type 0;
            
    $line5->entries[] = $entrie;

            
    $entrie = new ScorePacketEntry();
            
    $entrie->objectiveName "test";
            
    $entrie->type ScorePacketEntry::TYPE_FAKE_PLAYER;
            
    $entrie->customName "§r§7--------------------";
            
    $entrie->score 6;
            
    $entrie->scoreboardId 6;
            
    $line6 = new SetScorePacket();
            
    $line6->type 0;
            
    $line6->entries[] = $entrie;

            
    $packets = [$remove$title$line1$line2$line3$line4$line5$line6];
            
    $this->setResult($packets);
        }

        public function 
    onCompletion(\pocketmine\Server $server)
        {
            foreach(\
    pocketmine\Server::getInstance()->getOnlinePlayers() as $player)
            {
                foreach(
    $this->getResult() as $result)
                {
                    
    $player->sendDataPacket($result);
                }
            }
        }
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Mybe try create batch packet and add all the packets in it. Then just save the batch buffer. However does it works without 1 sec delay without async task?
     
    Primus likes this.
  3. Ectary Network

    Ectary Network Creeper

    Messages:
    2
    GitHub:
    xeww
    Nvm i'm fucking stupid it was because of my foreach in the onCompletion, i was sending the data of 1 player to everyone.
    Sorry for wasting your time and thanks you!
     
  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.