Hello. I am currently creating a plugin that requires data to be written to a yml file onDisable(). I have created a function that loops through my HashMaps that I have created and then uses this to write data to the YML. However, when this function is called, what is actually written is some wierd thing, where the last section is just not filled-in, and js instead just written as "*id001". The top section, while the data is actually written to it, has "&id001" mysteriously added to it. Here is the function that I use: Code:java public void saveData() { Main.getInstance().saveDefaultConfig(); ArrayList<Object> data = new ArrayList<Object>(); Main.getInstance().getConfig().set("ids", data); for(Location loc : Main.getInstance().idCoords.keySet()) { //Clears the arraylist data.clear(); //Generating a new section in the yml Main.getInstance().getConfig().createSection("ids.id_" + Main.getInstance().idCoords.get(loc)); data.add(loc.getBlockX()); //X Cord data.add(loc.getBlockY()); //Y Cord data.add(loc.getBlockZ()); //Z Cord data.add(loc.getWorld().getName()); //World data.add(Main.getInstance().itemTypes.get(Main.getInstance().idCoords.get(loc)).toString()); //ItemType data.add(Main.getInstance().itemMeta.get(Main.getInstance().idCoords.get(loc))); //ItemMeta if(Main.getInstance().adminIDs.contains(loc)) //Admin id check data.add("true"); else data.add("false"); //Storing the data Main.getInstance().getConfig().set("ids.id_" + Main.getInstance().idCoords.get(loc), data); } } Extra information, adminIDs is an ArrayList. All the other data I am calling comes from HashMaps EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Thanks for the suggestion, but made absolutely no difference. What the config.yml ends up as. Code: stores: store_3: &id001 - 516 - 66 - -138 - world - SAND - ==: ItemMeta meta-type: UNSPECIFIC - 'true' store_2: *id001 store_1: *id001
Hey, I added some comments to your code where I have Suggestions/Questions about it: Code:java public void saveData() { Main.getInstance().saveDefaultConfig(); ArrayList<Object> data = new ArrayList<Object>(); //What is this good for? You just created an empty array and then save it? Main.getInstance().getConfig().set("ids", data); //You iterate over a keyset to then later retreive the value. I would suggest using the entry set for your iteration. for (Location loc : Main.getInstance().idCoords.keySet()) { //Now you are using the ArrayList you already saved. What's the point of that? //Clears the arraylist data.clear(); //Generating a new section in the yml //What is the value type of the idCoords map? Is it a String? Main.getInstance().getConfig().createSection("ids.id_" + Main.getInstance().idCoords.get(loc)); data.add(loc.getBlockX()); //X Cord data.add(loc.getBlockY()); //Y Cord data.add(loc.getBlockZ()); //Z Cord data.add(loc.getWorld().getName()); //World data.add(Main.getInstance().itemTypes.get(Main.getInstance().idCoords.get(loc)).toString()); //ItemType data.add(Main.getInstance().itemMeta.get(Main.getInstance().idCoords.get(loc))); //ItemMeta if (Main.getInstance().adminIDs.contains(loc)) //Admin id check { data.add("true"); } else { data.add("false"); } //If you are just setting this as config, there is no need to create the sectio first. It is done automatically. //Storing the data Main.getInstance().getConfig().set("ids.id_" + Main.getInstance().idCoords.get(loc), data); } } While we could, generally speaking, get this to eventually work, it is way more complex than it needs to be. Bukkit provides us with an excellent serialization API for YAML files - so I woul suggest to make use of it. You can read about it here: http://wiki.bukkit.org/Configuration_API_Reference#Advanced_Topics I am also glad to help you getting started, if you describe you goal with this method regards, minoneer
minoneer In regards to your comments (in order): I set it to an empty array to clear it. Not sure if that is necessary, but I thought I'd add it to be sure I iterated over the keySet because I had to call the loc value several times. Again, you're right I could turn this around, but I don't really see the point I clear it because I am looping through the array several times so need to clear the data so that it is clean each time. Location, Integer Did not know that. I don't mean for this to seem like I am just giving blunt responses to your comments; I do sincerly appreciate the help. Regarding the API, I'll go read through that after posting this reply. The purpose of the function is simply to pull data out of a series of different hashMaps and store them in a YML onDisable().