1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Call to a member function setUsage() on nul

Discussion in 'Development' started by Bintang Putra, Jun 6, 2017.

  1. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Hi, i dont know what the error is
    I only got
    [Server thread/CRITICAL]: Error: "Call to a member function setUsage() on null" (EXCEPTION) in "/plugins/KEJURPG1/src/test/Main" at line 64


    PHP:
    public function onEnable()
    {
        
    $this->saveDefaultConfig();
        
    $this->reloadConfig();
        
    $this->saveResource("messages.yml"false);

        
    $messages = (new Config($this->getDataFolder() . "messages.yml"))->getAll();

        
    $this->messages $this->parseMessages($messages);

        
    $registerCommand $this->getCommand("register");
        
    $registerCommand->setUsage($this->getMessage("register.usage"));
        
    $registerCommand->setDescription($this->getMessage("register.description"));
        
    $registerCommand->setPermissionMessage($this->getMessage("register.permission"));

        
    $loginCommand $this->getCommand("login");
        
    $loginCommand->setUsage($this->getMessage("login.usage"));
        
    $loginCommand->setDescription($this->getMessage("login.description"));
        
    $loginCommand->setPermissionMessage($this->getMessage("login.permission"));

        
    $this->blockPlayers = (int)$this->getConfig()->get("blockAfterFail"6);

        
    $provider $this->getConfig()->get("dataProvider");
        unset(
    $this->provider);
        switch (
    strtolower($provider)) {
            case 
    "yaml":
                
    $this->getLogger()->info("Using YAML data provider");
                
    $provider = new YAMLDataProvider(new SimpleAuth());
                break;
            case 
    "sqlite3":
                
    $this->getLogger()->info("Using SQLite3 data provider");
                
    $provider = new SQLite3DataProvider(new SimpleAuth());
                break;
            case 
    "mysql":
                
    $this->getLogger()->info("Using MySQL data provider");
                
    $provider = new MySQLDataProvider(new SimpleAuth());
                break;
            case 
    "none":
            default:
                
    $provider = new DummyDataProvider(new SimpleAuth());
                break;
        }
    }


    private function 
    parseMessages(array $messages){
        
    $result = [];
        foreach(
    $messages as $key => $value){
            if(
    is_array($value)){
                foreach(
    $this->parseMessages($value) as $k => $v){
                    
    $result[$key "." $k] = $v;
                }
            }else{
                
    $result[$key] = $value;
            }
        }

        return 
    $result;
    }

    public function 
    getMessage($key){
        return isset(
    $this->messages[$key]) ? $this->messages[$key] : $key;
    }
    This post maybe a facepalm post :( . but, i need help, so i post it here
     
    Last edited by a moderator: Jun 6, 2017
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Did you register those commands in plugin.yml? Show your plugin.yml please.
     
  3. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    I Forgot To Register IT *facepalm
     
  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.