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

Problem get a list in a config.

Comments in 'Plugin Development' started by Player7221, Feb 27, 2016.

  1. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    I have a problem with get a list in a config.
    My code:
    Code:
                    foreach($this->getConfig()->get("sms.vip.info") as $i)
                    {
                        $sender->sendMessage($i);
                    }
                    return true;
    
    If i use command show errors:
    Code:
    [22:53:50] [Server thread/INFO]: An unknown error occurred while attempting to perform this command
    [22:53:50] [Server thread/CRITICAL]: Unhandled exception executing command 'sms' in sms: Invalid argument supplied for foreach()
    [22:53:50] [Server thread/WARNING]: RuntimeException: "Invalid argument supplied for foreach()" (E_WARNING) in "/Sms/src/Sms/Main" at line 36
    
    config.yml
    Code:
    ---
    sms:
      vip:
        info:
        - "32 Itemy"
        - "32 Diaxy"
    ...
    
    
    Help me, please.
  2. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Your config should be
    Code:
    sms.vip.info:
      - "32 Itemy"
      - "32 Diaxy"
    
    applqpak and Player7221 like this.
  3. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Other plugins have
    Code:
    Example:
      Example2:
        Example3:
        - "Text"
        - "Text"
    
    How I can make it?
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Config::getNested(), not Config::get()
    applqpak, Player7221 and Vaivez66 like this.
  5. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Thank you.
  6. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    How I can add color to config &?

    In java (spigot) is
    Code:
    ChatColor.translateAltrenateColorCodes('&', Main.getInstance().getConfig("...");
    But how is in PocketMineMP?
  7. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Use str_replace()
    applqpak and Player7221 like this.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    str_replace("&""§"$string);
    while $string is your string you want it to have it replaced
    applqpak and Player7221 like this.
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    It would be better to do an switch with
    case &1 replace TF::GREEN
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
     $string preg_replace('/&([0-9a-fk-or])/'"\xc2\xa7$1"$string);
    Last edited: Feb 28, 2016
    Legoboy0215 and applqpak like this.
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why? You then need to do that for every Color.
    PEMapModder, applqpak and Player7221 like this.
  12. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    use\pocketmine\... <-- for colors? Please help me...

    Code:
                        $i = preg_replace('/&([0-9a-f])/', "\xc2\xa7$1", $i);
    
    This don't work.
    Last edited: Feb 28, 2016
  13. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    PHP:
    $sender->sendMessage(str_replace('&''§'$i));
    @CraftYourBukkit already said that
    Player7221 likes this.
  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Future compatibly bla...
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Yes, but that might be changed
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For future compatibility, & may not even be reasonable to use anymore.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I prefer get instead of getNested.
  19. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    In that case, getNested does...
  20. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I simply gave him the correct code for what he wants. I didn't tell anyone to use getNested instead of get.
    Vaivez66 likes this.

Share This Page

Advertisement