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

How to do this?

Comments in 'Plugin Development' started by CraftYourBukkit, Jul 23, 2015.

  1. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I have a config like this:
    Code:
    idk:
       hey:
          d: 1
          f: 2
          b: 3
       hey1:
          d: 1
          f: 2
          b: 3
    and I want to have a command where I can list all "hey"s. Example:
    Command: /listh
    Output: hey, hey1

    I tried:
    PHP:
    $heys"";
                                foreach (
    $config->getNested("idk") as $hey) {
                                    if (
    $hey!== null) {
                                        
    $heys.= $hey", ";
                                    }
                                }
    But that gives this Error:
    Code:
    [Server] Server thread/NOTICE RuntimeException: "Array to string conversion" 
    So, how do I do this?
    Last edited: Jul 23, 2015
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Implode them.
    PHP:
    $heys "";
    foreach(
    $idk as $hey){
      
    $heys .= implode(", "$hey) . ", ";
    or
    PHP:
    $heys implode(", "array_merge(...$config->get("idk")));
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    $hey is an array ["d" => 1, "f" => 2, "b" =>3]
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is the expected output?
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $heys "";
                                foreach (
    $config->get("idk") as $hey) {
                                    if (
    $hey !== null) {
                                        
    $heys .= implode(", "$hey) . ", ";
                                    }
                                }
    ouputs d, f and b, not hey and hey1
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $out "";
    foreach(
    $config->get("idk") as $hey){
      
    $our .= implode(", "array_keys($hey));
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Also not working. I tried
    PHP:
    $out "";
    foreach(
    $config->get("idk") as $hey){
      
    $out .= implode(", "array_keys($config->get("idk")));
    which kinda worked, but the ouput was:
    Code:
    hey, heyhey1, hey1
    instead of
    Code:
    hey, hey1
    Last edited: Jul 23, 2015
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $out "";
    foreach(
    $config->get("idk") as $hey){
      
    $our .= implode(", "array_keys($hey)) . ", ";
    [/QUOTE]
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    [/QUOTE] That ouputs d, f and b again, not hey and hey1
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That ouputs d, f and b again, not hey and hey1[/QUOTE]
    Oh.
    PHP:
    $msg implode(", "array_keys($config->get(" idk")));
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That's what I tried. But it ouputs
    Code:
    hey, heyhey1, hey1
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That isn't even possible. You did something wrong. Maybe you called the function twice?
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    My code out of my plugin:
    PHP:
    $config = new Config($this->getDataFolder() . "players/" strtolower($sender->getName()) . ".yml"Config::YAML);
                            
    $number count($config->getNested("homes"));
                            if (
    $number === 0) {
                                
    $sender->sendMessage("§e§lHomes §8§l>> §r§cYou don't have a home yet.");
                                return 
    true;
                            } else {
                                
    $homes "";
                                foreach (
    $config->get("homes") as $home) {
                                    if (
    $home !== null) {
                                        
    $homes .= implode(", "array_keys($config->get("homes")));
                                    }
                                }
                                
    $sender->sendMessage("§e§lHomes §8§l>> §r§bYour Homes: §6" $homes);
                                return 
    true;
                            }
    Don't tell me to use TextFormat instead of Color Codes. xD
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why did you foreach? array_keys already returns all the keys in the array.
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Ahh now.. xD I didn't remove it because I had it before

Share This Page

Advertisement