Getting all indexes of a config file

Discussion in 'Plugin Development' started by rickydaan, Jan 26, 2014.

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

    rickydaan

    Hello Bukkiters,

    I was wondering how to get all of the indexes of a config file like this:
    Code:
    rickydaan:
      banned: false
      op: false
      ip: 127.0.0.1
      motto: "I love programming!"
    would return
    rickydaan
    rickydaan.banned
    rickydaan.op
    rickydaan.ip
    rickydaan.motto

    If you get what I mean

    Thank you all!
     
  2. Offline

    rangersmash

    getConfig().getConfigurationSection("rickydaan").getKeys(false) returns a array of the keys.

    then you can do
    for(String key : getConfig().getConfigurationSection("rickydaan").getKeys(false)){
    if(key.equals("banned"){

    }
    }
    So key represents :
    banned
    op
    ip
    motto
    :)
    rickydaan
     
  3. Offline

    Cammeritz

    Code:java
    1. cs.sendMessage("Banned: " + this.getConfig.getBoolean(args[0] + ".banned"));
    2. cs.sendMessage("Op: " + this.getConfig.getBoolean(args[0] + ".op"));
    3. cs.sendMessage("ip: " + this.getConfig.getString(args[0] + ".ip"));
    4. cs.sendMessage("motto: " + this.getConfig.getString(args[0] + ".motto));
    5. return true;
    6. //cs is the Command sender
    7. //if you want to use colorcodes with the motte, you should add ChatColor.translateAlternareColorCodes('&', this.getConfig().getString(args[0] + "motto"));
    8. //args[0] is the Playername
     
  4. Offline

    rickydaan


    I am working on a plugin so that you can edit config files from in-game. In order to do this, I need to be able to get all of the indexes. as essentials has other indexes than Mutliverse for example, you need to be able to get other indexes / values. I want it to be able to fit on every config file avaible.

    Cammeritz

    Please help me (Read post above)

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

    Cammeritz

    @rickydaanDo you want to change/ediit files of your own, or of other plugins?
     
  6. Offline

    rickydaan

    Cammeritz

    Of other plugins. Like if I'd open Essentials from my plugin, it'd show all of the options of /plugins/Essentials/config.yml
    And you could edit them. But you need to get those values of course.
     
Thread Status:
Not open for further replies.

Share This Page