Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with another plugin

Comments in 'Plugin Development' started by BlubberBoy333, Apr 24, 2016.

  1. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    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:
    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
  2. Intyre
    Offline

    Intyre Staff Member PocketMine Team

    Joined:
    Aug 24, 2013
    Posts:
    118
    Minecraft User:
    Intyre
    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
  3. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    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){
    BlubberBoy333 and applqpak like this.

Share This Page

Advertisement