I'm working on a plugin, and I wanted to compare a level(world) with another one matching from config file, Now there is a player I have whose world/level I want to compare but whenever I try that I get this error and I also have the same problem with checking for permissions, I really dont know why this occurs and this is making me crazy I'm tired of looking for a solution. Here is my code, there is a ! at the end of the lines with the error of this null thingy. Code: $perm = $this->plugin->getServer()->getPlayer($player)->hasPermission("beaconsplus.effect"); ! if($perm == false) { continue; } if($this->plugin->getServer()->getLevelByName($beaconLevel) == $this->plugin->getServer()->getPlayer($player)->getLevel()) ! { Please help me, I'm new to php though.
What is $player? getPlayer($player) is returning null instead of a Player object, which means getLevel was being called on null, thus the error.
this is the code before that Code: foreach($this->plugin->getServer()->getOnlinePlayers() as $player) { /*$perm = $this->plugin->getServer()->getPlayer($player)->hasPermission("beaconsplus.effect"); if($perm == false) { continue; }*/ if($this->plugin->getServer()->getLevelByName($beaconLevel) == $this->plugin->getServer()->getPlayer($player)->getLevel()) { if($this->plugin->getServer()->getPlayer($player)->distance($beaconPos) <= $this->plugin->getConfig()->get("beacon-range")) { what do u think is wrong with $player? is it suppoed to return the player
Why do you get the player of a player $server->getOnlinePlayers() already returns an array of players, not an array of player names.
After you foreach the online players, you don't need to use Server->getPlayer, because you already have the Player object to use.