Saving a Hashmap to config.yml

Discussion in 'Plugin Development' started by Mrmime, Jun 13, 2015.

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

    Mrmime

    Hello everyone!

    I just can't find how to save this hasmap in my config.yml

    public static Map<String , String> commands = new HashMap<String, String>();

    Please help me
     
  2. Online

    timtower Administrator Administrator Moderator

    @Mrmime config.set("location",commands);
     
    seanliam2000 likes this.
  3. Offline

    Mrmime

    That works! how do i load it back in?
     
  4. Online

    timtower Administrator Administrator Moderator

    @Mrmime Tried config.get already?
     
  5. Offline

    Mrmime

    I have not, how would i use this to put every element in the hashmap?
     
  6. Online

    timtower Administrator Administrator Moderator

    @Mrmime Try the method first. Then show code if still not sure what to do.
     
  7. Offline

    Mrmime

    System.out.println(getConfig().getConfigurationSection("location").getKeys(false));
    this returns []
     
  8. Online

    timtower Administrator Administrator Moderator

    @Mrmime a configurationSection is not a hashmap.
     
  9. Offline

    Mrmime

    i really don't know how to do this...
     
  10. config.get("path.to.value"); and cast to HashMap
     
  11. Offline

    Mrmime

    So this is my config atm
    location:
    hello: test
    would i do config.get("location?");
    (the hello:test is suppost to be in location)
     
  12. Online

    timtower Administrator Administrator Moderator

    @Mrmime Try to work with configurationSections instead of with Hashmaps as you are doing now.
     
  13. Offline

    Mrmime

    Are you sure there is no way of doing this :(
     
  14. Online

    timtower Administrator Administrator Moderator

    @Mrmime Lets start with this: show you example config and tell us how you want to use it.
     
  15. Offline

    Mrmime

    location:
    test: give @p stone​
    It puts the text on a sign and a command in a hashmap
    so when you right click a sign with that text it executes that command
     
  16. Online

    timtower Administrator Administrator Moderator

    @Mrmime configurationSection.getKeys(false)
    Loop through the keys, get the values, add them to the hashmap.
    When adding a new sign: add it to the hashmap, and at the same time add it to the config.
     
  17. Offline

    Mrmime

    how do i know i got a key instead of a value
     
  18. Online

    timtower Administrator Administrator Moderator

    @Mrmime I know, tried config.get(value) already?
    And please use the tahg or reply button when responding to somebosy, then they will get an alert about it.
     
  19. Offline

    Mrmime

    So config.get(value) and then config.get(key) and put them both in a hashmap?
     
  20. Online

    timtower Administrator Administrator Moderator

    @Mrmime That is what you want right?
     
  21. Offline

    Mrmime

    config.get(value) what am i suppost to put instead of value
     
  22. Online

    timtower Administrator Administrator Moderator

    @Mrmime
     
  23. Offline

    Mrmime

    @timtower
    Set<String> keys = config.getConfigurationSection("location").getKeys(false);
    for (String s : keys) {
    System.out.println(s);​
    }

    This returns the keys, how do i do the values

    @timtower
    i figured it out!
    Map<String, Object> values = config.getConfigurationSection("location").getValues(true);
    thanks for your help!

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jun 14, 2015
Thread Status:
Not open for further replies.

Share This Page