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

Add Players into a .yml

Comments in 'Plugin Development' started by Marcelo234, Feb 21, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys.....There is a "game.yml"...It looks like that:
    Code:
    ---
    gamemembers: ""
    ...
    So..There I want that my Plugin write all PlayerNames of some choosen Players!
    PHP:
    $this->game = new Config($this->getDataFolder()."Locations/game.yml"Config::YAML);
    $this->game->set("gamemembers""$player1,$player2");
    So here I add two Names of different Players! But what must I write, if I want to add a NEW Player? Because if I write it like that the old Players will delete and only the NEW Player will be stand there! So maybe something with a +?
    Thanks Marcelo234
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    maybe
    PHP:
    $this->game->set("gamemembers"$this->game->get("gamemembers"), $player3);
    And why is it so
    Code:
    "$player1,$player2"
    and not so
    Code:
    $player1,$player2
    ?
    Last edited: Feb 21, 2016
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    You are using some bad practise but here is what you have to do then
    Foreach new player
    PHP:
    NewPlayer "BLA";
    OldPlayers Config::get("gamemembers");
    Config::set("gamemembers"OldPlayers NewPlayer);
    Last edited: Feb 25, 2016
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Lol, we posted at the same time
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

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

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    This isn't Java.
    AndrewBit likes this.
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Forum = English only, still. And well, it's bad to save all of them into a config, but here:
    PHP:
    $this->game = new Config($this->getDataFolder()."Locations/game.yml"Config::YAML);
    $old $this->game->get("gamemembers");
    $a explode(","$old);
    array_push($a$newPlayer);
    $new implode(","$a);
    $this->game->set("gamemembers"$new);
    $this->game->save();
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    function addMemberToConfig(Config $config, array $memberNames){
      
    $config->set("gamemembers"array_merge($memberNames$config->get("gamemembers", [])));
    }
    matthww likes this.
  9. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    So now.. Thanks....but how to delete a choosen player? And how to Test if the Playername is written there....
  10. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    JavaScript*
  11. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    So anyone can tell me how to remove a player from list and how to Check is the Playername is in the Config?
    Thanks Marcelo234
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    To check: strpos(). To remove: explode(), then unset(), then implode()
  13. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Why is this java? I used static codes because you cannot assume that $this has config used!
  14. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    What..? using . instead of -> is Java, not using $ on variables is java, and missing ;
  15. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Yay... Java... I like Java...
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Edited my post a bit
    And with . I meant the string glue

Share This Page

Advertisement