@Override protected void save(ConfigurationSection config) { super.save(config); ConfigurationSection costsSection = config.createSection("costs"); int count = 0; for (ItemStack item : costs.keySet()) { Cost cost = costs.get(item); ConfigurationSection itemSection = costsSection.createSection(count + ""); itemSection.set("item", item); String attr = NMSManager.getProvider().saveItemAttributesToString(item); if (attr != null && !attr.isEmpty()) { itemSection.set("attributes", attr); } itemSection.set("amount", cost.amount); itemSection.set("item1", cost.item1); itemSection.set("item2", cost.item2); count++; } }
@Override protected void load(ConfigurationSection config) { super.load(config); costs = new HashMap<ItemStack, Cost>(); ConfigurationSection costsSection = config.getConfigurationSection("costs"); if (costsSection != null) { for (String key : costsSection.getKeys(false)) { ConfigurationSection itemSection = costsSection.getConfigurationSection(key); ItemStack item = itemSection.getItemStack("item"); if (itemSection.contains("attributes")) { String attr = itemSection.getString("attributes"); if (attr != null && !attr.isEmpty()) { item = NMSManager.getProvider().loadItemAttributesFromString(item, attr); } } Cost cost = new Cost(); cost.amount = itemSection.getInt("amount"); cost.item1 = itemSection.getItemStack("item1"); cost.item2 = itemSection.getItemStack("item2"); costs.put(item, cost); } } }