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

Adventure with Player::sendPosition()

Discussion in 'Development' started by gistrec, Feb 11, 2017.

  1. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    Hi all
    I would like to create function, witch teleport player to spawn, when he fall
    PHP:
    public function PlayerFallEvent(EntityDamageEvent $event){
        if(
    $event->getEntity()->getLevel()->getName() == self::LOBBY_NAME){
            if (
    $event->getEntity() instanceof Player && $event->getCause() == 4) {
                
    $event->setCancelled();
                
    $event->getEntity()->teleport(new Vector3(self::Xself::Yself::Z));
             }
         }
    }
    But sometimes, than this event is happens, server start spam in console error message (very-very fast spam)
    Code:
    [Server thread/DEBUG]: BatchPacket 0x78da1396123fdaf4c1898141c5298bbdd989f11f0b0303ab2a83f13a4711290e649979602919110690e0c32a2db0e07b057747decc358740988111af2400984722a1
    [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\Player::sendPosition() must be an instance of pocketmine\math\Vector3, null given, called in src/pocketmine/Player.php on line 2239" (EXCEPTION) in "src/pocketmine/Player" at line 3917
    [Server thread/DEBUG]: #0 /src/pocketmine/network/Network(253): pocketmine\Player->handleDataPacket(pocketmine\network\protocol\MovePlayerPacket object)
    [Server thread/DEBUG]: #1 /src/pocketmine/Player(2099): pocketmine\network\Network->processBatch(pocketmine\network\protocol\BatchPacket object, pocketmine\Player Player(1))
    [Server thread/DEBUG]: #2 /src/pocketmine/network/RakLibInterface(139): pocketmine\Player->handleDataPacket(pocketmine\network\protocol\BatchPacket object)
    [Server thread/DEBUG]: #3 /src/raklib/server/ServerHandler__64bit(94): pocketmine\network\RakLibInterface->handleEncapsulated(string 91.202.71.251:50887, raklib\protocol\EncapsulatedPacket `.(e..a.....Bx....?.....A.)..........*..:G.).d.y`)......*-..{.wG..5.@....$..G"., integer 0)
    [Server thread/DEBUG]: #4 /src/pocketmine/network/RakLibInterface(74): raklib\server\ServerHandler->handlePacket(boolean)
    [Server thread/DEBUG]: #5 /src/pocketmine/network/Network(156): pocketmine\network\RakLibInterface->process(boolean)
    [Server thread/DEBUG]: #6 /src/pocketmine/Server(2644): pocketmine\network\Network->processInterfaces(boolean)
    [Server thread/DEBUG]: #7 /src/pocketmine/Server(2378): pocketmine\Server->tick(boolean)
    [Server thread/DEBUG]: #8 /src/pocketmine/Server(2256): pocketmine\Server->tickProcessor(boolean)
    [Server thread/DEBUG]: #9 /src/pocketmine/Server(1860): pocketmine\Server->start(boolean)
    [Server thread/DEBUG]: #10 /src/pocketmine/PocketMine(479): pocketmine\Server->__construct(pocketmine\CompatibleClassLoader object, pocketmine\utils\MainLogger object, string /home/server/mcpeServer/, string /home/server/mcpeServer/, string /home/server/mcpeServer/plugins/)
    I try a lot of way to solve this problem: update pmmp, editing Player.php and so on...
    But I found one solution: I use callback in my function, witch teleport Player after 1 tick
    PHP:
    // I change
    $event->getEntity()->teleport(new Vector3(self::Xself::Yself::Z));
    // To
    $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$event->getEntity(),"teleport"], [new Vector3(self::Xself::Yself::Z)]), 1);
    But now, player normally teleport, but server write 1 error message:
    Code:
     Notice: Object of class pocketmine\scheduler\CallbackTask could not be converted to float in src/pocketmine/utils/Binary.php on line 388
    Very nice, in 388 line I have function
    PHP:
    public static function writeLFloat($value){
        return 
    ENDIANNESS === self::BIG_ENDIAN strrev(pack("f"$value)) : pack("f"$value);
    }
    I var dump'ed $value, when server write error msg
    Code:
    object(pocketmine\scheduler\CallbackTask)#18210 (3) {
      ["callable":protected]=>
      array(2) {
        [0]=>
        object(pocketmine\Player)#11669 (0) {
        }
        [1]=>
        string(8) "teleport"
      }
      ["args":protected]=>
      array(2) {
        [0]=>
        object(pocketmine\math\Vector3)#18215 (3) {
          ["x"]=>
          float(55.5)
          ["y"]=>
          int(55)
          ["z"]=>
          float(62.5)
        }
        [1]=>
        *RECURSION*
      }
      ["taskHandler":"pocketmine\scheduler\Task":private]=>
      object(pocketmine\scheduler\TaskHandler)#18217 (8) {
        ["task":protected]=>
        *RECURSION*
        ["taskId":protected]=>
        int(105)
        ["delay":protected]=>
        int(1)
        ["period":protected]=>
        int(-1)
        ["nextRun":protected]=>
        int(193)
        ["cancelled":protected]=>
        bool(false)
        ["timings"]=>
        object(pocketmine\event\TimingsHandler)#18218 (9) {
          ["name":"pocketmine\event\TimingsHandler":private]=>
          string(67) "Task: Scheduler Runnable: pocketmine\scheduler\CallbackTask(Single)"
          ["parent":"pocketmine\event\TimingsHandler":private]=>
          object(pocketmine\event\TimingsHandler)#141 (9) {
            ["name":"pocketmine\event\TimingsHandler":private]=>
            string(25) "** Scheduler - Sync Tasks"
            ["parent":"pocketmine\event\TimingsHandler":private]=>
            NULL
            ["count":"pocketmine\event\TimingsHandler":private]=>
            int(0)
            ["curCount":"pocketmine\event\TimingsHandler":private]=>
            int(0)
            ["start":"pocketmine\event\TimingsHandler":private]=>
            int(0)
            ["timingDepth":"pocketmine\event\TimingsHandler":private]=>
            int(0)
            ["totalTime":"pocketmine\event\TimingsHandler":private]=>
            int(0)
            ["curTickTotal":"pocketmine\event\TimingsHandler":private]=>
            int(0)
            ["violations":"pocketmine\event\TimingsHandler":private]=>
            int(0)
          }
          ["count":"pocketmine\event\TimingsHandler":private]=>
          int(0)
          ["curCount":"pocketmine\event\TimingsHandler":private]=>
          int(0)
          ["start":"pocketmine\event\TimingsHandler":private]=>
          int(0)
          ["timingDepth":"pocketmine\event\TimingsHandler":private]=>
          int(0)
          ["totalTime":"pocketmine\event\TimingsHandler":private]=>
          int(0)
          ["curTickTotal":"pocketmine\event\TimingsHandler":private]=>
          int(0)
          ["violations":"pocketmine\event\TimingsHandler":private]=>
          int(0)
        }
        ["timingName"]=>
        string(33) "pocketmine\scheduler\CallbackTask"
      }
    }
    And can you help?)
    How can I normally teleport my player when he fall
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    You are not using pmmp.
    pocketmine\scheduler\CallbackTask does not exist anymore. You're not supposed to be using it. And i doubt that the error happens if you'd happen to use pmmp.
     
    gistrec likes this.
  3. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    I try to use pmmp and genisys :3
    But, I try again
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    make your own call back task under anonymous class to avoid core forks conflicts
     
    gistrec likes this.
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Callback tasks are generally not needed.
     
    gistrec likes this.
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Just switch to pmmp and use the initial code. if that still fails, open an issue at PM.
     
  7. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    I make a lot of change in core and can't simply change it to pmmp :'c
    Thanks
     
  8. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    This is exactly why you should fork projects, NOT 'spoon' them, so you can merge changes to PMMP into your own fork. You could start afresh by forking PMMP and integrating your own changes back into the fork.
     
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    We do not provide support for Genisys.
     
    gistrec likes this.
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    but there nothing wrong using them
     
    gistrec likes 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.