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

Solved Get all config "entries"

Comments in 'Plugin Development' started by AppPhil, Oct 3, 2015.

  1. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    Hey there,

    I have a config.yml where I saved things like this:
    Code:
    test: true
    something: false
    Now I got this code and when I run the plugin it gives me something like true false:
    Code:
    foreach($this->cfg->getAll() as $w) {
        $this->getLogger()->info($w);
    }
    So I get the values of "test" and "something".
    But now I want to get the keys of every entry and not the value of them. How can I do that?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
     foreach($this->cfg->getAll() as $key => $w){
      
    // log $key instead of $w
    }
    AppPhil likes this.
  3. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    Thanks! Works fine!
  4. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    @PEMapModder
    Got a new problem now.
    I have this code inside a PluginTask:
    PHP:
    foreach($this->plugin->cfg->getAll() as $key => $w){
        
    $key explode("_"$key); 
        
    $world $key[0];
        
    $map $this->plugin->getServer()->getLevelByName($key[0]);
        if(
    $w == true) {
            
    $this->plugin->getLogger()->info(TF::GREEN."True");
         } else {
            
    $this->plugin->getLogger()->info(TF::GREEN."False");
         }
    }
    I have keys like "world_day" with true or false as value. And then I get the text before the "_" and get the world with that name. I want to change the time in the world, when it's false as an example, but if the value is false it prints out "True" too. I don't know why the if-thing isn't working. So the problem is not that I don't know how to change the time. The problem is, that when $w is false it prints out "True".
    Last edited: Oct 3, 2015
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try doing var_dump($w).
    AppPhil likes this.
  6. AppPhil
    Offline

    AppPhil Active Member

    Joined:
    Oct 3, 2015
    Posts:
    54
    @PEMapModder
    Gives out string(5) "false" and string(4) "true".
    I changed this:
    PHP:
    if($w == true) {
    to:
    PHP:
    if($w === "true") {
    and now it works! Thanks again!

Share This Page

Advertisement