Saving/loading Hashmaps

Discussion in 'Plugin Development' started by Wantsome909, Dec 21, 2013.

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

    Wantsome909

    how would you save/load a hash map with integers?
     
  2. Offline

    1Rogue

    What have you tried so far?
     
    Garris0n likes this.
  3. Offline

    Wantsome909

    1Rogue not much that all i got
    Code:java
    1. public Map<String, Integer> PlayerMoney = new HashMap<String, Integer>();


    i don't know how to save or load
     
  4. Offline

    1Rogue


    You should probably attempt writing some actual code before asking for advice on it really.

    Basic IO: http://docs.oracle.com/javase/tutorial/essential/io/

    Alternatively you could write it in yaml by iterating over the contents of your map. But at least write something first.
     
  5. Offline

    Wantsome909

    1Rogue
    Code:java
    1. public Map<String, Integer> points = new HashMap<String, Integer>();
    2. @Override
    3. public void onEnable() {
    4. PluginManager pm = getServer().getPluginManager();
    5. pm.registerEvents(this, this);
    6. for(String str: getConfig().getKeys(true)) {
    7.  
    8. int p = getConfig().getInt(str);
    9.  
    10. points.put(str, p);
    11. }
    12. }
    13.  
    14. @Override
    15. public void onDisable() {
    16. for(Entry<String, Integer> pointstostore: points.entrySet()) {
    17.  
    18. getConfig().set(pointstostore.getKey(), pointstostore.getValue());
    19. }
    20. saveConfig();
    21. }

    here some code
     
  6. Offline

    1Rogue


    Did you just copy/paste that from here?:
    https://forums.bukkit.org/threads/save-hashmap-to-a-config-yml.106651/#post-1384606

    The entire reason I don't want to just give you code is because you should learn what it does, not copy/paste.
     
  7. Offline

    Wantsome909

    1Rogue no i didn't my friend show me and he told me all about how to save and load hashmaps.
    but thank you anyway!
     
Thread Status:
Not open for further replies.

Share This Page