Solved True of False Config File

Discussion in 'Plugin Development' started by Begreen98, Feb 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Begreen98

    I have my Configuation File being generated and that works, but I can't figure out how to get things from that Config File. I need to get this line:
    config.set("Effects.HurtFromSick", "true");
    and have it so if Effects.HurtFromSick is set as True then it will do something.
    Thank you.
     
  2. Offline

    RealDope

    getConfig().getString("path.to.string");
    getConfig().getBoolean("path.to.boolean");
    getConfig().getInt("path.to.int");
    etc
     
  3. Offline

    Begreen98

    I tried doing this:
    Code:
    if (getConfig().getString("Effects.HurtFromSick.True") != null){
    player.addPotionEffect(new PotionEffect(PotionEffectType.POISON,
    500, 1));
    }
    but now it doesn't do it at all no matter the if it is set as True or False
     
  4. Offline

    danthonywalker

    No no no.

    Your "this.whatever" is the path.

    Say it's

    Code:
    I:
      am:
        a:
          path:
    It would setup like "I.am.a.path" You're looking for the value for the final path. So say it was like

    Code:
    I:
      am:
        a:
          path: IAmAString
    You would so plugin.getConfig().getString("I.am.a.path"), it then returns the value for that in this case it would return a string "IAmAString". It could be an Int, String, boolean, and a few others.
     
  5. Offline

    Begreen98

    I don't really understand what you're suggesting, can you explain it a little more? Maybe an example please?
     
  6. Offline

    RealDope

    Let's say this is your config:
    Code:
    Begreen98:
      Amount: 1
      Reason: Some Random Reason
    
    Now lets say you wanted to get what the "reason" was under your name:
    Code:JAVA
    1.  
    2. String reason = getConfig().getString("Begreen98.Reason");
    3. System.out.println(reason);
    4. // Prints out "Some Random Reason"
    5. Int amount = getConfig().getInt("Begreen98.Amount");
    6. System.out.println(amount);
    7. // Prints out "1"
    8.  
     
  7. Offline

    danthonywalker


    Ok so in your config you set it up like this, remember YAML files do not like Tabs, use 2 spaces whenever going down the list.

    Code:
    I:
      am:
        a:
          path:
    Each of those things are called nodes. A node never has a specific value, it just acts like an organization for your YAML files. When you're trying to call a value, say a string, you want to find the nodes, NOT the actual value.

    In your case when you did "Effects.HurtFromSick.True" I am assuming your thing looks like this.

    Code:
    Effects:
      HurtFromStick: true


    But what you were doing I can assume is that you were trying to act as if True was a node when it isn't. That's the value. Your code is calling for a value, the nodes only act as a guidence.

    So you would do plugin.getConfig().getBoolean("Effects.HurtFromStick"), this will return the value from the node HurtFromStick that's under Effects. Kind of get it?
     
  8. Offline

    Begreen98

    That helps me understand how to get the value, but not how to make it so if that Value is true to do something. What I currently have it as is
    Code:
    if plugin.getConfig().getBoolean("Effects.HurtFromSick"){
                    player.addPotionEffect(new PotionEffect(PotionEffectType.POISON,
                            500, 1));
                }
     
  9. Offline

    danthonywalker

    YAML files also process things differently. Believe it or not true is actually a stirng, not a boolean value, if you want to a boolean value it would be Yes or No. Kind of weird, but if you want to know.

    http://en.wikipedia.org/wiki/YAML#Data_types

    If you really want to make it so your config does true or false just do plugin.getConfig().getString("yourpath").equals("true")
     
  10. Offline

    Begreen98

    Thank you so much! That works!
     
Thread Status:
Not open for further replies.

Share This Page