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
You mean save the CommandSender's name inside? Is your command something like /command add {playername}?
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
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
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.
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
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.
There is an easier easier way PHP: case "list": $list = $this->plugin->vips->getAll(); $sender->sendMessage("VIPs (" . count($list) . "): " . implode(", ", $list)); return true;
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.
https://github.com/lovemy10a8/VipPlus/blob/master/src/Main/Main.php pls go to this page and help me fixing about case "list". I'm so confusing about this