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

How can i make list from a file:

Comments in 'Plugin Development' started by TheKillerTacos, Feb 10, 2016.

  1. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Hi! im making DonateRanks, a plugin request by a user,
    so i want to make a list,
    e.g
    the plugin makes the
    ranks.yml,
    so when they run the command
    /donate ranks list 1
    they get:
    ---------Rank List: [1/4]------------
    1. Vip
    2. Vip+
    3. Admin
    4. Rank

    and making list, so i thinkg using arrays or something. please help!
  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    In config:
    Code:
    Admin
    VIP
    VIP+
    
    OR:
    Ranks: - Admin
                 - VIP
                 - VIP+
    
    Then do:
    PHP:
    $player->sendMessage("---[LIST]---");
    foreach(
    $this->getConfig()->getAll() as $rank){
    $player->sendMessage($rank);
    }

    And 
    on the Ranksexample
    foreach($this->getConfig()->get("Ranks") as $rank){
    .. 
    code
    }
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You should also take a look at the VIPSlots plugin
  4. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    if you need to change this list often , you can save an array in "ranks.yml"
    using \pocketmine\utils\Config
    example:
    PHP:
    $list = (new Config($pathConfig::YAML, ['line1''line2''line3''line4']))->getAll();

    foreach(
    $list as $line){
    Player->sendMessage($line);
    }
    if you don't need to change this list , simply send messanges to the sender of the command
    PHP:
    $sender->sendMessage('line1');
    $sender->sendMessage('line2');
    $sender->sendMessage('line3');
    //or just 1 message using End Of Line
  5. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    I do need to change the list, since youll be adding the ranks on a rank.yml
  6. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    PHP:
    $player->sendMessage("---[LIST]---");
    foreach(
    $this->getConfig()->getAll() as $rank){
    $player->sendMessage($rank);
    }

    And 
    on the Ranksexample
    foreach($this->getConfig()->get("Ranks") as $rank){
    .. 
    code
    }
    .. code ?
  7. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    ok, on plugin enable "onEnable" add this code to save the file into the plugin folder:
    PHP:
    @mkdir($this->getDataFolder); //makes the folder
    new Config($this->getDataFolder.'ranks.yml'Config::YAML, ['line1''line2''line3''line4'/*add how many you want*/]);
    when a player run the command use this code to send the list:
    PHP:
    //you must define $path
    $list = (new Config($pathConfig::YAML, ['line1''line2''line3''line4']))->getAll();

    foreach(
    $list as $line){
    Player->sendMessage($line);
    }

Share This Page

Advertisement