[1.8] YAML Sets / Configuration sections with null values

Discussion in 'Spigot Plugin Development' started by Mike_x1, Jun 22, 2016.

  1. Hello,

    I am currently creating a plugin using a lot of configuration and encountered a rather big problem with loading said configuration files.

    In the first version I was using simple lists for several conditions I needed to parse. This is what the code looked like:
    Code (Text):
    - chance(chance)<>
    - chance(chance2)<>
    However, I need more functionality than using a list of conditions, so I have decided to switch to a more advanced type of configuring things. I am now trying to use configuration sections for my conditions, making the config look like either of these two versions (that should theoretically be the same in YAML syntax):
    First option using the YAML set syntax:
    Code (Text):
            ? chance(chance)<>
            ? chance(chance2)<>
        ? chance(chance3)<>
    Second option using null as values:
    Code (Text):
            chance(chance)<>: null
            chance(chance2)<>: null
        chance(chance3)<>: null

    I've double-checked my code.
    When debugging my project, neither of the two options gives me any values in the "conditions" configuration section. I just get an empty map. No exceptions whatsoever are thrown either.

    My code used to read the config section is as follows:
    Code (Text):
    if (triggerSection.contains("conditions")) {
        final ConfigurationSection conditionsSection = triggerSection.getConfigurationSection("conditions");
        for (String conditionKey : conditionsSection.getKeys(false)) {
                    callProcedure, conditionsSection.getConfigurationSection(conditionKey)
    The "triggerSection" variable is what you see at the very top of the debug screen. It contains the conditions section in the config.

    As a side note, loading this DOES work when I use the second one of the provided options (in the "Configurations" spoiler) and replace null with any value that is NOT null.

    Hope any of you can help me with this issue.

    Thanks in advance
    - Mike
  2. In yml null = remove from the config. That is probably why you are having this problem.

    Maybe set it to 'null' (like a string that says null instead of just null)?
  3. First of all, thanks for your answer :)

    So I assume I can't use YAML sets with snakeyaml and/or Bukkit at all?
  4. You could just add an isNull option