Next available option in a path

Discussion in 'Plugin Development' started by mazentheamazin, Jan 7, 2014.

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

    mazentheamazin

    Hi,

    Currently I am trying to make a plugin that in the config it has something like this:
    Code:
    variables:
      variable1: 24
      variable2: 32
      variable3: 2343 
    Now variable1, 2 and 3 can be changed (In terms of names), so I want to know how I can go down the list of available paths (Like getConfig().getString("variables.variable1")). Sort-of like a ladder.

    Thanks,
    Mazen
     
  2. Offline

    xBlackLightx

    I may be misunderstanding you, but if I get what you're asking, bukkit automatically sorts them like a ladder. For example if you were to do something such as:
    Code:java
    1. getConfig().set(Test1.Test2, "Hi");

    Your config would look like:
    Test1:
    Test2: Hi

    So if you had in your config:

    variables:
    variable1:
    variable2:
    etc....

    to get the value of variable 1, you would do exactly as you said, using getConfig().getString(variables.variable1).
    If I misunderstood what you were asking, just let me know.
     
  3. Offline

    mazentheamazin

    xBlackLightx
    Not really, let me explain a little bit. So, lets say the plugin makes it so you can sell a item for a certain price so it would be like this:
    Code:
    Items:
      322: 23 <-- Price
      1: 120
    How would I get these items from that path, I know you can use list's but I can't use them for this plugin.
     
  4. Offline

    xTrollxDudex

  5. Offline

    mazentheamazin

    xTrollxDudex
    Mind showing me an example of how I can go down the list? Like you're going down a ladder. For example, like a list.. You can do list.get(number); would there be a way to do it like that?
     
  6. Offline

    xTrollxDudex

    mazentheamazin
    PHP:
    for(String key getConfig().getConfigurationSection("Items").getKeys(false)) {
        
    String base "Items.";
        
    String prePrice base key

        int actualPrice 
    getConfig().getInt(prePrice);
    }
     
  7. Offline

    mazentheamazin

    xTrollxDudex
    Thank you soo much! Don't mind if I ask one more thing, but how would I check the position of the key.. its due to the fact that I want to see if its the last available path.
     
  8. Offline

    xTrollxDudex

    mazentheamazin
    You can check if key is equal to a specific string. Otherwise, I have no idea.
     
Thread Status:
Not open for further replies.

Share This Page