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

[MySql] How to get the Player in a function?

Discussion in 'Development' started by LewBr, Oct 23, 2017.

  1. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Hello everybody, i need help whit some code..
    I have an error on my Console that i don't know how to fix, like i am using MySql server to get player data, score anyways, and i have an error:

    because i want to get on a function if the player has this permission then return something..
    but i don't know how to do that because i am receiving that error:
    PHP:
    23.10 15:48:11 [ServerServer thread/CRITICAL Could not execute task leohardu\LeoHarduEntidade\TextosTrying to get property 'hasPermission' of non-object
    23.10 15
    :48:11 [ServerServer thread/CRITICAL ErrorException"Trying to get property 'hasPermission' of non-object" (EXCEPTIONin "LeoHarduCore/src/leohardu/LeoHarduEntidade/Textos" at line 73
    23.10 15
    :48:11 [ServerServer thread/DEBUG #0 LeoHarduCore/src/leohardu/LeoHarduEntidade/Textos(73): pocketmine\error_handler(integer 8, string Trying to get property 'hasPermission' of non-object, string /plugins/LeoHarduCore/src/leohardu/LeoHarduEntidade/Textos.php, integer 73, array Array())
    23.10 15:48:11 [ServerServer thread/DEBUG #1 LeoHarduCore/src/leohardu/LeoHarduEntidade/Textos(117): leohardu\LeoHarduEntidade\Textos->Test(string RiquelmeMaciel)
    23.10 15:48:11 [ServerServer thread/DEBUG #2 src/pocketmine/scheduler/TaskHandler(160): leohardu\LeoHarduEntidade\Textos->onRun(integer 601)
    23.10 15:48:11 [ServerServer thread/DEBUG #3 src/pocketmine/scheduler/ServerScheduler(326): pocketmine\scheduler\TaskHandler->run(integer 601)
    23.10 15:48:11 [ServerServer thread/DEBUG #4 src/pocketmine/Server(2506): pocketmine\scheduler\ServerScheduler->mainThreadHeartbeat(integer 601)
    23.10 15:48:11 [ServerServer thread/DEBUG #5 src/pocketmine/Server(2253): pocketmine\Server->tick()
    23.10 15:48:11 [ServerServer thread/DEBUG #6 src/pocketmine/Server(2132): pocketmine\Server->tickProcessor()
    23.10 15:48:11 [ServerServer thread/DEBUG #7 src/pocketmine/Server(1714): pocketmine\Server->start()
    23.10 15:48:11 [ServerServer thread/DEBUG #8 src/pocketmine/PocketMine(558): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string phar:///custom7.2.phar/, string /, string /plugins/)
    23.10 15:48:11 [ServerServer thread/DEBUG #9 /custom7.2.phar(1): require(string phar:///custom7.2.phar/src/pocketmine/PocketMine.php)
    Please help?
    Code:
    Task
    PHP:
      public function Test($p){

            if (
    $p->hasPermission == "teste.teste"){
                return 
    "Hi";
            }
            else {
                return 
    "Hello";
            }
        }

    //Task file
    $ranking1 $this->plugin->getTestMy();
    foreach(
    $ranking1 as $place1){
    ".$this->Test($place1['name'])."
    }
    //Task file
    Main
    PHP:
      public function getTestMy(){
            
    $result $this->provider->db->query("SELECT * FROM `rede_geral` ORDER BY `test` DESC LIMIT 1 OFFSET 0");
            return 
    $result;
        }
    Sorry about english.
     
    Last edited: Oct 23, 2017
  2. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    First:
    PHP:
    public function Test($p){
        if(!
    $p instanceof Player) return;
            if (
    $p->hasPermission == "teste.teste"){
                return 
    "Hi";
            }
            else {
                return 
    "Hello";
            }
        }
    then:
    Store the name on your databse not the player because this isn't a variable, when you added the name to make the name as a player jusy check if a player with that name is online and get it with getServer()->getPlayer()
     
  3. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Ok. but i want to get if the player is offline too, not only online :confused: i'm confused
     
  4. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    boi just do
    PHP:
    if(!$this->getServer()->getPlayer($name)){
        return; 
    // Offline
    }
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    /** @var OfflinePlayer|Player $player **/
    $player $this->getServer()->getOfflinePlayer($playerName)->getPlayer() ?? $this->getServer()->getOfflinePlayer($playerName);
     
    Muqsit 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.