Solved Getting Specific Values From Config.yml HELP!

Discussion in 'Plugin Development' started by odogollie, Oct 8, 2012.

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

    odogollie

    Hello,

    I am looking for help with the config.yml.
    Basicly I have a Config file and it has:
    Code:
    dirt:
      price: 2
    stone:
      price: 3
    cobblestone:
      price: 1
    Dirt, Stone, and Cobblestone are based upon what the player inputs in the command like:
    Code:
    /stock price dirt
    How would I go about getting the price from that?

    Note:
    I have been able to get the price with just:
    Code:
    dirt: 2
    stone: 3
    cobblestone: 1
    I have other things I will add later.
     
  2. Offline

    ZeusAllMighty11

    To get price of dirt:

    getConfig().getInt("Dirt.Price");

    Should be that anyway
     
  3. Offline

    gomeow

    ZeusAllMighty11 Mind your capitalization

    Use this, as stated above:
    Code:
    getConfig().getInt("Path.to.String");
    Which would take from:
    Path:
    to:
    String:
     
  4. Offline

    odogollie

    Well I get that, but I don't want to write that for every possible item. Is there another way to do that? If I do:
    Code:
    String item = args[1].toLowerCase();
    I get that you can do:
    Code:
    getConfig().getString(item);
    But only when the config looks like:
    Code:
    dirt: 2
    stone: 3
    etc...
     
  5. Offline

    gomeow

    Sorry about that, my code didn't format right, it would take from
    Code:
    Path:
      to:
        String:
    
    I don't understand what you're asking

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  6. Offline

    Drkmaster83

    I believe he's trying to get values in the config by using the String "item".
     
  7. Offline

    odogollie

    Well yes basically and the String item is defined by the user input of args[1]
     
  8. Offline

    gomeow

    Ah, I see, try this:
    Code:
    String item = args[1].toLowerCase;
    getConfig().getInt(item + ".price");
    
     
  9. Offline

    odogollie

    YES!!!! GAHH thank you!
     
  10. Offline

    gomeow

    Your welcome
     
  11. Offline

    Devil0s

    You should use another external YAML file because config is actually to set settings of your plugin.
    It's much better to store that informations in a prices.yml or something like this.
     
  12. Offline

    gomeow

    That would be a good idea in a bigger plugin, but to start learning, I think he should use the config for now
     
  13. Offline

    Devil0s

    There isnt any bigger different between config.yml and another YAML file, but ok.
    I respect your opinion. :D
     
  14. Offline

    ZeusAllMighty11


    I store locations in the config.YML ... As long as the user with the plugin isn't dumb enough to edit it, it's fine.
    Plus, config has a built in API, other YML files don't.
     
  15. Offline

    gomeow

    Other YML files are a little harder to make and use
     
  16. Offline

    Devil0s

  17. Offline

    ZeusAllMighty11

  18. Offline

    Devil0s

    No problem. :D
     
  19. Offline

    odogollie

    oh another quick question, how do i change the values of the price?
     
  20. Offline

    Devil0s

    Something like
    Code:
    getConfig().set("path.to.object", int amount);    
    To change the price of an apple to 4.
    Code:
    getConfig().set("apple.price", 4);
     
  21. Offline

    odogollie

    thank you! i will test that when i get there!

    and using the String item it would be?
    Code:
    getConfig().set(item + ".price", int);
     
  22. Offline

    Devil0s

    I hope that it works.
    I dont use configs at the moment.
    But it should work.
     
  23. Offline

    gomeow

    That should be right
     
  24. Offline

    odogollie

    now... when I use double it sends me back a really long number like 1.99337848...
    How do I make it float to 2 decimals?
     
  25. Offline

    gomeow

    Where are you getting that double from?
     
  26. Offline

    odogollie

    it was something like:
    Code:
    double price = getConfig().getDouble(item + ".price")
     
  27. Offline

    gomeow

    Do you plan on having non-integer price values?
     
  28. Offline

    odogollie

    I would have values like 1.95, like normal monetary values
     
  29. Offline

    gomeow

  30. Offline

    odogollie

    My plugin changes the value based off how many are in the "stock." So when someone buys one, the stock rises and my equation is an exponential decay function. After using doubles and buying one dirt, I use /stock price dirt and it is a strangely long decimal like I said above.
     
Thread Status:
Not open for further replies.

Share This Page