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

A clear way to write to a config file?

Comments in 'Plugin Development' started by jasonwynn10, Mar 5, 2016.

  1. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    So, I have been experimenting with different ways to save data to my config file every time my plugin is disabled. So far, I have found nothing that works easily, consistently, or in the way I was expecting. So, I'm asking if a plugin developer here has a clear concise way to write to a config file. Also, If you could take a look at my plugin here: https://github.com/LostTeam/SpawnInvis I would be grateful of your help.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As a matter of fact, config means configuration, which means options, which means to let the user edit options like server.properties and pocketmine.yml. Why do you love using config.yml to save data so much?

    Anyway, in your code:
    HotFireyDeath likes this.
  3. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    In the disable function, I had a bit of code that was supposed to save the last setting to the config. I removed it and let there be return statements instead because it didn't work. I want to replace those with a working method of saving to the config file.
    Last edited: Mar 5, 2016
  4. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    My Methode is to usw config.yml :
    PHP:
    Public $Text1;
    Public function 
    onEnable(){
    $this->getLogger()->info("was activated");
    @
    mkdir($this->getDataFolder() . "config.yml);
    If (empty->get("
    Text1"){
    $config->set("Text1" , "Text1");
    }
    $this->Text1 = $config->get("Text1");
    }
    Public Function onCommand (CommandSender 
    $sender , Command $cmd$label, array $args){
    Switch(strtolower(
    $event->getName()){
    case "
    info" :
    $sender->sendMessage($this->Text1);
    Return true;
    }
    I hope i helped you :p.They are maybe any mistakes because i tipped on my mobile phone with german auto-correction xD.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    empty->get("Text1") ? And don't blame translator!
    Last edited: Apr 1, 2016
    PEMapModder likes this.
  6. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    xD
    i mean
    PHP:
    if( empty($config->get("Text1"))){
    $config->set("Text1" "Text1);
    }
    As i wrote it i was very tired and didn't think about it :D.
  7. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    I'm a jerk xD. I forgot many things wait :
    Before:
    PHP:
    @mkdir($this->getDataFolder() . "config.yml");
    After x:eek:
    PHP:
    @mkdir($this->getDataFolder());
    $config = new Config ($this->getDataFolder() . "config.yml" Config::YAML);
    Last edited: Apr 1, 2016
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You have to close your quotes when creating string!
    HotFireyDeath likes this.
  9. WitherTube
    Offline

    WitherTube New Member

    Joined:
    Dec 21, 2015
    Posts:
    44
    Minecraft User:
    Wither_Tube
    I made it but i corrected my mistakes in the following code xD

Share This Page

Advertisement