1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Help me to create the list of player in 1 file

Discussion in 'Plugin Help' started by GOdly, Nov 29, 2016.

  1. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    I have a plugin and i just add the player to file in that plugin. And now i want see those players that i added to file. So what can i do ?
    $this->vips = new Config($this->getDataFolder() . "vips.txt", Config::ENUM);
    That's file save the player
     
  2. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    You mean save the CommandSender's name inside? Is your command something like /command add {playername}?
     
    GOdly likes this.
  3. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    PHP:
    //add player
    //MUST DEFINE $player!!

    //add player
    $this->vips->set($player->getName(), $this->player->getName());

    //get player
    $this->vips->get($player->getName());

    //remove player
    $this->vips->remove($player->getName());

    //save list
    $this->vips->save();
    See all config methods here:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/utils/Config.php
     
    SOFe, HimbeersaftLP and GOdly like this.
  4. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    which i mean is Can you guys help me how to do the command (/sth list) to show my pplayersthat i saved in files in my server
     
  5. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    what is the get for ???
     
  6. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    To get a value from the config array.
     
    HimbeersaftLP and GOdly like this.
  7. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    haha, I just need the /command list, and it will show all the players in 1 file
     
  8. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
    foreach($this->vips->getAll() as $vip) {
        
    $player->sendMessage($vip);
    }
    This might help you. Configs can be seen as an array theirselves, which allows you to foreach() them.
     
    HimbeersaftLP likes this.
  9. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    PHP:
    case "list":
            
    $list "";
            foreach(
    $this->plugin->vips as $vip){
              if(
    strlen($list) > 0){
                
    $list .= Color::WHITE ", ";
                
    $list .= $vip;
              }
            }
            
    $sender->sendMessage("VIPs (" count($this->plugin->vips) . "): " $list);
            return 
    true;
    Survingo wrote this for me. But when i use this command, only i can get is: VIPs (): .... it dont show the name
     
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You might want to try to add ->getAll() to both
    PHP:
    $this->plugin->vips
    so you get
    PHP:
    $this->plugin->vips->getAll()
    I'm not sure if that will work, but you could try.
     
  11. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    Okay, Let me try :p
     
  12. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    No, that not Work,
     
  13. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    There is an easier easier way
    PHP:
    case "list":
            
    $list $this->plugin->vips->getAll();
            
    $sender->sendMessage("VIPs (" count($list) . "): " implode(", "$list));
            return 
    true;
     
    Kenn Fatt, Primus, GOdly and 2 others like this.
  14. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    tks you
     
  15. Primus

    Primus Zombie Pigman

    Messages:
    749
    I guess you have to use rtrim to get rid off leading ", "
    PHP:
    rtrim(implode(", "$list), ", ");
     
  16. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    There won't be an extra comma.
     
  17. Primus

    Primus Zombie Pigman

    Messages:
    749
    true
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This is irrelevant to the question... What matters is how he saves it, not when he saves it.
    implode only puts the delimiter between elements.
    strlen($list) will never be executed.
    You should put $list .= $vip; outside the if block:
    PHP:
            foreach($this->plugin->vips as $vip){
              if(
    strlen($list) > 0){
                
    $list .= Color::WHITE ", ";
              }
              
    $list .= $vip;
            }
    Or you can actually use the key from foreach, assuming the array is linear:

    PHP:
    foreach($this->plugin->vips as $i => $vip){
        if(
    $i !== 0$list .= Color::WHITE ", ";
        
    $list .= $vip;
    }
    Also, please use TextFormat instead of Color. I don't understand why so many prefer to use aliases in public and formal code examples.
     
    HimbeersaftLP and Sandertv like this.
  19. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    I hope this is right code. Right ??
     
  20. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.