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

Remove a value from an array config

Comments in 'Plugin Development' started by AvivShopenCraft, May 18, 2016.

  1. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    I have this:
    PHP:
    Badwords:
    word1
    word2
    word3
    lets say i want to remove word2 from the list, but i cant find solution,
    ive tried:
    PHP:
    $words $this->cfg->get("Badwords");
    unset(
    $words["word2"]);
    $this->cfg->set("Badwords"$words);
    $this->cfg->save();
    but it dont seems to work...:(
    Any other ways?
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Is the first one a config a cornflakes packet a shampoo whats the first file?
  3. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    what do you mean lol
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    What is $this->cfg?
  6. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    I think $this->cfg = new Config(blabla, Config::YAML);
    and not used in main file
  7. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    May someone help me please?
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    $path $this->getServer()->getDataPath()."plugins/MyPlugin/config.yml";

    file_put_contents(str_replace("- badword2"""file_get_contents($path)), $path);
  9. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Instead Server::getDataPath() method, why not use directly getDataFolder()?
    PHP:
    $path $this->getDataFolder() . "file.yml";
  10. _Neisufek_
    Offline

    _Neisufek_ New Member

    Joined:
    Apr 17, 2016
    Posts:
    16
    Minecraft User:
    xNaisu
    It's not a big deal, guys. Just unset the index.
    PHP:
    if(isset($this->cfg["Badwords"])){
    unset(
    $this->cfg["Badwords"][0]);//unset word 1
    unset($this->cfg["Badwords"][1]);//unset word 2
    //etc...
    }

Share This Page

Advertisement