Server thread/CRITICAL Error: "Call to a member function get() on null" (EXCEPTION) in "plugins/Mine

Discussion in 'Development' started by M4nt0s, Sep 4, 2019.

  1. M4nt0s

    M4nt0s Spider Jockey

    Messages:
    30
    GitHub:
    M4nt0s
    I have some problems with using the config.yml. Its all set up but it is crashing all time i try the command. onCommand the plugin is looking if the "editor" is equal with "unset"(Here could be a gamertag or something else too.) And on this point it kicks me out of the server.


    PHP:
    class main extends PluginBase implements Listener{
        public 
    $cfg;

        public function 
    onLoad() : void{
            
    $this->getLogger()->info(TextFormat::WHITE "I've been loaded!");
        }

        public function 
    onEnable() : void{
    if(!
    is_dir($this->getDataFolder())){
        @
    mkdir($this->getDataFolder());
    }
    $this->saveResource("config.yml");
    if(!
    file_exists($this->getDataFolder()."config.yml")){
        
    $this->cfg = new Config($this->getDataFolder()."config.yml"Config::YAML);
    if(!
    $this->cfg->get("editor")){
            
    $this->cfg->set("editor""unset");
            }
    }

    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(TextFormat::DARK_GREEN "I've been enabled!");
        }

        public function 
    onDisable() : void{
            
    $this->getLogger()->info(TextFormat::DARK_RED "I've been disabled!");
        }

    public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool{
            if(
    strtolower($command->getName()) === "mf"){

    if(
    $args[0] == "create"){
    $p $sender->getPlayer();
    $editor $this->cfg->get("editor");
    if(
    $this->cfg->get($this->cfg->get("editor")) == "unset"){
    $this->cfg->set("editor"$p->getName());
    }else{
    $sender->sendMessage("Another player is using the editor!");
    }
    }
    }
    }
    }
     
  2. wolfdale

    wolfdale Zombie

    Messages:
    358
    Remove this line
    if(!file_exists($this->getDataFolder()."config.yml"))
     

Share This Page

  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.