Yaml list of key/values to java List of objects

Discussion in 'Plugin Development' started by GDorn, Feb 10, 2011.

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

    GDorn

    I'm more of a python dev than a java dev and prefer json to yaml, so a bunch of this is unfamiliar territory for me. Here's a rough idea of what I'd like to be able to put into the config.yml:

    Code:
    log_level:  WARN
    contraption_material: OBSIDIAN
    fail_chance: 3
    recipes:
        - product: DIAMOND
          type: item
          reagent1: COAL_ORE
          reagent2: OBSIDIAN
          reagent3: CLOCK
        - product: COAL_ORE
          type: block
          reagent1: WOOD
          reagent2: COBBLESTONE
          reagent3: INK_SAC
          reagent3_data: BLACK
          reagent3_consumed: true
        - product: HUGE_SLIME
          type: mob
          reagent1: WATER
          reagent2: WATER
          reagent3: SLIMEBALL
          reagent3_consumed: true
    
    I know how to parse the top-level elements (log_level, contraption_material, etc) and have done so in my forks of various other plugins.

    The point I'm having trouble getting past is the recipes section. It is essentially a list of length N, containing groups of key/value pairs. I have a Recipe class which I would like to create N instances of by passing each group to the constructor. I have no idea how to do this, yet it is probably absurdly trivial.

    In python, it would look something like this:
    Code:
    config = yaml.load(my_file)
    recipes = config['recipes']
    all_recipe_objects = [Recipe(data) for data in recipes]
    
    What's the equivalent incantation in java, preferably taking advantage of the getConfiguration() method provided by Bukkit's JavaPlugin?
     
Thread Status:
Not open for further replies.

Share This Page