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 [Server] Server thread/CRITICAL Could not execute task leohardu\LeoHarduEntidade\Textos: Trying to get property 'hasPermission' of non-object23.10 15:48:11 [Server] Server thread/CRITICAL ErrorException: "Trying to get property 'hasPermission' of non-object" (EXCEPTION) in "LeoHarduCore/src/leohardu/LeoHarduEntidade/Textos" at line 7323.10 15:48:11 [Server] Server 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 [Server] Server thread/DEBUG #1 LeoHarduCore/src/leohardu/LeoHarduEntidade/Textos(117): leohardu\LeoHarduEntidade\Textos->Test(string RiquelmeMaciel)23.10 15:48:11 [Server] Server thread/DEBUG #2 src/pocketmine/scheduler/TaskHandler(160): leohardu\LeoHarduEntidade\Textos->onRun(integer 601)23.10 15:48:11 [Server] Server thread/DEBUG #3 src/pocketmine/scheduler/ServerScheduler(326): pocketmine\scheduler\TaskHandler->run(integer 601)23.10 15:48:11 [Server] Server thread/DEBUG #4 src/pocketmine/Server(2506): pocketmine\scheduler\ServerScheduler->mainThreadHeartbeat(integer 601)23.10 15:48:11 [Server] Server thread/DEBUG #5 src/pocketmine/Server(2253): pocketmine\Server->tick()23.10 15:48:11 [Server] Server thread/DEBUG #6 src/pocketmine/Server(2132): pocketmine\Server->tickProcessor()23.10 15:48:11 [Server] Server thread/DEBUG #7 src/pocketmine/Server(1714): pocketmine\Server->start()23.10 15:48:11 [Server] Server 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 [Server] Server 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.
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()
PHP: /** @var OfflinePlayer|Player $player **/$player = $this->getServer()->getOfflinePlayer($playerName)->getPlayer() ?? $this->getServer()->getOfflinePlayer($playerName);