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

How to "$this->config->set".

Comments in 'Plugin Development' started by Angelo Vidrio, Jan 10, 2015.

  1. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Hello, I was wondering if there is anyway to do this without replacing whats already set for that config file. For example, I will do
    Code:
    $this->config->set("Player",  [$player2,]);
    and then if that player is already set in the config file with
    Code:
    ---
    Player:
    - Player2
    It will just replace Player2, I want to be able to ADD to Player.
    Last edited: Jan 10, 2015
  2. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    you want to replace Player2 with what? i dont get what you mean :/
  3. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    No, Im trying no to replace Player2, im trying to ADD to Player to make
    Code:
    ---
    Player:
    - Player2
    - Player3
    instead of - Player2 just being replaced by $player2 in
    Code:
    $this->config->set("Player",  [$player2,]);
    xFlare likes this.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I don't know how to do that in a one liner but you can do:
    PHP:
    $player $this->config->get("Player");
    $player[] = "Player2";
    $this->config->set("Player",  $player);
  5. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    Dont forget this! :p
    PHP:
    $this->config->save();
    $this->config->getAll();
    Falk, hoyinm14mc and Angelo Vidrio like this.
  6. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    without getAll() is ok.
  7. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    I know about that but
    When I do your method all it does is still replace the first line under Player:, not adding one
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $this->config is a property private e to PluginBase. Use $this->getConfig() instead.
  9. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    But I have multiple configs so I use $this->factionsPro = new Config($this->getDataFolder() . "players.yml", CONFIG::YAML, array(
    PEMapModder likes this.
  10. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    Code:
    private $temp = array();
    
    if(!isset($this->temp['Player'])){
    $empty = this->config->get("Player");
    if(!empty(array_filter($empty)){
    $drumstick = array();
    }else{
    $drumstick = $empty;
    }
    $this->temp['Player'] = $drumstick;
    $array = array_push($this->temp['Player'], $player2);
    $this->config->set("Player", $array);
    unset($this->temp['Player']);
    }
    
    im not sure if it works but pls try it out.
    Angelo Vidrio and xFlare like this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yep but don't name it $config.
  12. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    So what name should I use... Give me an example:)
  13. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    \
    Yessss!! I had this bug in my plugin I been trying to solve for a week, Now that you said that I understand why he bug was happening!
  14. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    getConfig() is not usable..
  15. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    if you used it the wrong way, yes.
    hoyinm14mc likes this.
  16. Mariachi
    Offline

    Mariachi New Member

    Joined:
    Oct 11, 2014
    Posts:
    23
    Minecraft User:
    Mariachi
    The what what?
    How to learn php?
    I'll make plugins if you show me where :D
  17. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    google it
  18. Mariachi
    Offline

    Mariachi New Member

    Joined:
    Oct 11, 2014
    Posts:
    23
    Minecraft User:
    Mariachi
    Can you show me where you learned?
  19. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Read tutorials and on php.net
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Keep reading examples, that's how I learnt.
    It is. Actually you should not define $this->config yourself. Blame whoever started this nasty trend.
    hoyinm14mc and iJoshuaHD like this.

Share This Page

Advertisement