data.yml hashmap

Discussion in 'Plugin Development' started by IsThisNameTakenNope, Jul 29, 2014.

Thread Status:
Not open for further replies.
  1. all I want to do is add a data.yml and store the data of the player, and the amount of blocks broken from a hashmap? I tried using the wiki but it's confusing. :/
  2. Offline


    This is a bit complicated.. Are you sure you can't use the config.yml?
  3. Offline


    You can use this class for Bukkit yaml files.

    To use just do.

    1. //In Class
    2. private YamlDatabase database;
    4. //On Enable
    5. this.database = new YamlDatabase(this, "data");
    6. this.database.onStartUp();
    8. //On Disable
    9. this.database.onShutDown();
    11. //To use within methods
    12. this.database.getInteger("", 2/*A return value if nothing is at the given path*/);
    14. //The above goes for all types

    Now for what you want something like this.

    1. HashMap<String, Integer> blocksBroken = new HashMap<String, Integer>();
    3. public void load() {
    4. for(String player : this.database.getSection("", new ArrayList<String>())) {
    5. blocksBroken.put(player, this.database.getInteger(player, 0);
    6. }
    7. }
    9. public void save() {
    10. for(String player : blocksBroken.getKeySet()) {
    11. this.database.set(player, blocksBroken.getValue(player));
    12. }
    13. }

    Some of the HashMap methods might be wrong haven't used hashmaps in a long time.
  4. @Beeperdp I can use the config.yml, it's just the .set for the config wont set anything in the config
    and messageofdeath I put the last part of your code in my Main class and I get errors on getValue and getKeySet
    I'll check replies in the morn'
  5. Offline


    You have to correct the hashmap methods but everything else is fine. Also with that you have to save the file.

    If you use the api I put it saves automatically.
Thread Status:
Not open for further replies.

Share This Page