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

Configs

Discussion in 'Plugin Help' started by CupidonSauce173, Oct 1, 2018.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    So I want to create a config with a player name
    like : cupidonsauce173.yml
    and in it it would be like that

    name = cupidonsauce173
    fakename = []

    I have some issues with getting the fakename to change the DisplayName of the player. it's with
    /setfakename <fakename>

    PHP:
        public function getFakeName(IPlayer $player$onUpdate false)
        {
            
    $name $player->getName();

            if(
    $onUpdate === true)
            {
                if(!
    file_exists($this->userDataFolder strtolower($name) . ".yml"))
                {
                    return new 
    Config($this->userDataFolder strtolower($name) . ".yml"Config::YAML, [
                        
    "name" => $name,
                        
    "fakename" => [],
                    ]);
                }
                else
                {
                    return new 
    Config($this->userDataFolder strtolower($name) . ".yml"Config::YAML, [
                    ]);
                }
            }
            else
            {
                if(
    file_exists($this->userDataFolder strtolower($name) . ".yml"))
                {
                    return new 
    Config($this->userDataFolder strtolower($name) . ".yml"Config::YAML, [
                    ]);
                }
                else
                {
                    return [
                        
    "name" => $name,
                        
    "fakename" => [],
                    ];
                }
            }
        }
    But I am not sure how to get "name" and "nick" from the config file. If someone could help it would be good.

    PHP:
                case "setfakename":
             
                    if(!
    $sender instanceof Player)
                    {
                        
    $sender->sendMessage(TextFormat::RED " This command can be only used in-game.");
                     
                        return 
    true;
                    }
                 
                    if(!isset(
    $args[0]))
                    {
                        
    $sender->sendMessage(TextFormat::GREEN "Usage: /setfakename <fakename>");
                     
                        return 
    true;
                    }
                               
                    
    $fakename str_replace("{BLANK}"' 'implode(''$args));
                                 
                    
    $sender->setDisplayName($fakename);
                 
                    
    $sender->sendMessage(TextFormat::GREEN " You set your fakename to " $fakename ".");
                 
                    break;
    I mean, I want to make it so when the player do /setfakename <fakename> it will change the [] in config for the args that he put and then save it.
     
  2. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    getFakeName returns the config in one case and an array in the other..

    If it would only return a config, you could use $config= $this->getFakeName(); $config->set("name", $fakename); and save the config afterwards with $config->save();
     
  3. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    ok thanks for the help
     
    XenialDan likes this.
  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.