PlayerJoinEvent

Discussion in 'Development' started by ZackyVN, Mar 19, 2019.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    124
    I try to create a player account when a player join first time
    My attemps:
    PHP:
        public function onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $this->createPlayerAccount($player);
            
    $this->sendInfo($player);
        }

        public function 
    accountExists(Player $player){
            
    $playername strtolower($player->getName());
            
    $result $this->db->query("SELECT * FROM dataVayCuaNguoiChoi WHERE tenplayer='".$this->db->real_escape_string($playername)."'");
            return 
    $result->num_rows true:false;
        }
       
        public function 
    createPlayerAccount(Player $player){
            
    $playername strtolower($player->getName());
            if(!
    $this->accountExists($player)){
                
    $this->db->query("INSERT INTO dataVayCuaNguoiChoi (tenplayer, sotiendavay) VALUES ('".$this->db->real_escape_string($playername)."', '0');");
            }
        }
    But when a player first join, it send this error
    Code:
    2019-03-19 [13:00:28] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to MrDinoDuck\Casino\Main::accountExists() must be an instance of pocketmine\Player, string given, called in C:\Users\Administrator\Desktop\Minecraft\Server test plugin\plugins\Casino\src\MrDinoDuck\Casino\Main.php on line 67" (EXCEPTION) in "plugins/Casino/src/MrDinoDuck/Casino/Main" at line 59
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #0 plugins/Casino/src/MrDinoDuck/Casino/Main(67): MrDinoDuck\Casino\Main->accountExists(string mrdinoduck)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #1 plugins/Casino/src/MrDinoDuck/Casino/Main(47): MrDinoDuck\Casino\Main->createPlayerAccount(string mrdinoduck)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #2 plugins/Casino/src/MrDinoDuck/Casino/Main(55): MrDinoDuck\Casino\Main->isNew(pocketmine\Player object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #3 src/pocketmine/plugin/MethodEventExecutor(38): MrDinoDuck\Casino\Main->onJoin(pocketmine\event\player\PlayerJoinEvent object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #4 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(MrDinoDuck\Casino\Main object, pocketmine\event\player\PlayerJoinEvent object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #5 src/pocketmine/event/Event(99): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerJoinEvent object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #6 src/pocketmine/Player(1080): pocketmine\event\Event->call()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(297): pocketmine\Player->doFirstSpawn()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket(45): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleSetLocalPlayerAsInitialized(pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(109): pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #10 src/pocketmine/network/mcpe/protocol/BatchPacket(119): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(109): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #12 src/pocketmine/Player(3111): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #13 src/pocketmine/network/mcpe/RakLibInterface(170): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #14 vendor/pocketmine/raklib/src/server/ServerHandler(99): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.1.9 63012, raklib\protocol\EncapsulatedPacket object, integer 0)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #15 src/pocketmine/network/mcpe/RakLibInterface(110): raklib\server\ServerHandler->handlePacket()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #16 src/pocketmine/network/mcpe/RakLibInterface(100): pocketmine\network\mcpe\RakLibInterface->process()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #17 vendor/pocketmine/snooze/src/SleeperHandler(123): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #18 vendor/pocketmine/snooze/src/SleeperHandler(85): pocketmine\snooze\SleeperHandler->processNotifications()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #19 src/pocketmine/Server(2329): pocketmine\snooze\SleeperHandler->sleepUntil(double 1552975228.6575)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #20 src/pocketmine/Server(2187): pocketmine\Server->tickProcessor()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #21 src/pocketmine/Server(1766): pocketmine\Server->start()
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #22 src/pocketmine/PocketMine(250): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\Administrator\Desktop\Minecraft\Server test plugin\, string C:\Users\Administrator\Desktop\Minecraft\Server test plugin\plugins\)
    2019-03-19 [13:00:28] [Server thread/DEBUG]: #23 (1): require(string phar://C:/Users/Administrator/Desktop/Minecraft/Server test plugin/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
     
  2. TheClimbing

    TheClimbing Spider Jockey

    Messages:
    32
    GitHub:
    theclimbing
    PHP:
    public function onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            if(!
    $this->playerExists($player) ) {
             
    $this->createPlayerAccount($player);
              
    $this->sendInfo($player) ;
             }
        }
    This should work, sorry that I can't write the full code but you get the idea. For some reason the object is lost I don't see you overwriting $player. So that should be it
     
  3. wolfdale

    wolfdale Zombie

    Messages:
    258
    Code:
    MrDinoDuck\Casino\Main->createPlayerAccount(string mrdinoduck)
    
    public function createPlayerAccount(Player $player){
            $playername = strtolower($player->getName());
            if(!$this->accountExists($player)){
                $this->db->query("INSERT INTO dataVayCuaNguoiChoi (tenplayer, sotiendavay) VALUES ('".$this->db->real_escape_string($playername)."', '0');");
            }
        }
    
    This would have already thrown an exception, but since it didnt, the code you shown us doesnt match the code that is executed. Btw the code you provided alr works
     
  4. MusicNOvas

    MusicNOvas Silverfish

    Messages:
    21
    $event->setJoinMessage("Message " . $player->getName());
     
  5. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    this post is not relevant to the question, also, don't bump threads
     

Share This Page

  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.