List all Strings in a Configuration Section

Discussion in 'Plugin Development' started by Blockhead7360, Jun 16, 2015.

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

    Blockhead7360

    Hello once again!

    So I am making a plugin. Here is the config:

    Code:
    notes:
      test: 'hello'
      test2: 'hello'
      test3: 'hello'
    Basically, I want to some how get the configuration section called "notes" and display all the values in it in-game.

    So in-game, I want it to be like:

    "Here are the notes:
    test: hello
    test2: hello
    test3: hello
    "

    I don't want to make a String List, because I need to have the names "test, test2, test3" associated with the text.

    If you understand, can anyone please help?
     
  2. Offline

    sam_0208

    Can't you just use getConfig().get("notes").toString ?
     
  3. Offline

    TehHypnoz

    I think it's something like this, can't check right now:

    Code:
    for (String key : getConfig().getConfigurationSection("notes").getKeys(true)) {
    String string = getConfig().getString("notes." + key);
    // Do something with the string
    }
    
     
  4. Offline

    Blockhead7360

  5. Offline

    sam_0208

    You can also set test as a path itself

    test: "Hello"
    test2: "Hello"
    etc

    And get them with getConfig().getString("test").toString()
     
  6. Offline

    Zombie_Striker

    @Blockhead7360
    Why do something like the following:
    Code:
    ArrayKeeper:
       notes:{test1,test2}
    notes:
       test1:'hi'
       test2:'hi2'
     
  7. Offline

    timtower Administrator Administrator Moderator

    You don't need to call toString on a string
     
  8. Offline

    Blockhead7360

    What do you mean?
     
  9. Offline

    sam_0208

    Code:
    notes:
      test: 'hello'
      test2: 'hello'
      test3: 'hello'
    instead of that you can use
    Code:
    test: "Hello"
    test2: "Hello"
    test3: "Hello"
    and if you want to send it you use
    p.sendMessage(getConfig().getString("test"))
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    SuperOriginal

    This is a way of doing it, I spread it out and added comments so you can understand better.

    Code:
            //returns the list of keys at the given configuration section, in this case it'd be test, test2, and test3
            //We're specifing 'false' as the paramater to getKeys() because we don't want a deep search.
            Set<String> keys = getConfig().getConfigurationSection("CONFIG-SECTION-HERE").getKeys(false);
       
            //loop through it
            for(String key : keys){
                //retrieve the value pair of the key
                String value = getConfig().getString("CONFIG-SECTION-HERE." + key);
           
                //Broadcast code here. You now have access to the key and value to do as you wish.
            }
     
  12. Offline

    Blockhead7360

    @timtower @SuperOriginal @sam_0208 @TehHypnoz @Zombie_Striker

    It doesn't work. Is it because of this?

    config.yml in Eclipse:

    Code:
    # KeepNotes Configuration
    # KeepNotes by Blockhead7360
    
    # Check out my website: http://blockhead7360.weebly.com
    
    # REMEMBER: This is FULLY configurable in-game! Check out /note config
    # However, messages that you want might not fit in the Minecraft chat bar
    
    ############
    #          #
    # Settings #
    #          #
    ############
    
    # A few settings for the plugin
    
    settings:
    
    # --- Simplified Help Menu ---
    
    # This setting toggles between displaying all the aliases in the notes
    # help menu.
    # true > It will show all aliases, separated by white "|"s
    # false (default) > It will just show the main arguments
    # Nothing you do here will stop these aliases: ex. /notes add and /addnote
    
    
    simple-help: false
    
    
    
    ############
    #          #
    # Messages #
    #          #
    ############
    
    # Edit all the KeepNotes messages here!
    
    prefix: '&0[&2Keep&aNotes&0]'
    
    
    messages:
      no-permission: '&cAccess Denied.'
    
    
    
    
    
    
    
    notes:
      red: hi
      yellow: hi
      green: hi
    but then config.yml on the server:

    Code:
    # KeepNotes Configuration
    # KeepNotes by Blockhead7360
    #
    # Check out my website: http://blockhead7360.weebly.com
    #
    # REMEMBER: This is FULLY configurable in-game! Check out /note config
    # However, messages that you want might not fit in the Minecraft chat bar
    
    messages: {}
    notes: {}
    
    Is it because of that? Is there a way that I could fix that? I have saveDefaultConfig();
     
  13. Offline

    timtower Administrator Administrator Moderator

    @Blockhead7360 Remove all comments and blank lines from the config in eclipse.
     
Thread Status:
Not open for further replies.

Share This Page