So I'm working on a plugin that lets you ban players from worlds. And in the plugin I have a function that checks if the player is banned in the world. Code for that function is in a spoiler below: Spoiler Code: public function checkBan(Level $level, Player $player){ $file = new Config($this->getDataFolder()."Levels/".$this->getServer()->getLevel($level)->getName().".yml"); if($file->get($player->getName()) !== null){ if($file->get($player->getName()) == "Banned"){ return true; }else{ return false; } }else{ if($this->getServer()->getPlayer($player) instanceof Player){ $file->set($player->getName(), "Allowed"); return false; }else{ return false; } } } So when someone uses the command to ban the player from a world, I get this error message: Unhandled exception executing command 'worldban RxThunderHD world' in worldban: Call to a member function getName() on null [17:44:52] [Server thread/CRITICAL]: Error: "Call to a member function getName() on null" (EXCEPTION) in "/PerWorldBan_v0.0.1/src/Blubberboy333/PerWorldBan/Main" at line 29 Could anyone please tell me why it is doing this and how to fix this? Thanks in advance
Use google to find out what that error means: http://bfy.tw/5R1v You're not the first person with that kind of error (About 2.030.000 results) Let's split up the error message: - Call to a member function - getName() - on null Read it as: null->getName() Learn how to debug: http://php.net/manual/en/debugger.php
Not sure if this is the issue but: Code: }else{ if($this->getServer()->getPlayer($player) instanceof Player){ $file->set($player->getName(), "Allowed"); $player was already a Player instance, so Code: $this->getServer()->getPlayer($player) returns null, so the next line would have errors. And you don't have to check if it's an instance of Player; it has to be because of this: public function checkBan(Level $level, Player $player){