Here is what I did for a very similar situation. I just nested the whole yml file in one tab and added a map label: at the top. So for your business it will be.
map: 19: typeID: 2 limit: 300 20: typeID: 8 limit: 100
And then create a static class in your class that reads this file as shown below.
static class Items { public Map<Integer, Item> map; }
And then, to read your card, just use.
Yaml yaml = new Yaml(new Constructor(Items)); Items items = (Items) yaml.load(<file>); Map<Integer, Item> itemMap = items.map;
UPDATE:
If you do not want or cannot edit your yml file, you can simply perform the above conversion in code when reading a file with something like this.
try (BufferedReader br = new BufferedReader(new FileReader(new File("example.yml")))) { StringBuilder builder = new StringBuilder("map:\n"); String line; while ((line = br.readLine()) != null) { builder.append(" ").append(line).append("\n"); } Yaml yaml = new Yaml(new Constructor(Items)); Items items = (Items) yaml.load(builder.toString()); Map<Integer, Item> itemMap = items.map; }
source share