Configured

Configured

33M Downloads

List-based config options that are empty by default are turned into boolean lists in Configured GUI

connor135246 opened this issue ยท 3 comments

commented

This is probably related to #15.
If a list-based config option's default value is an empty list, and then the player adds values in the Configured GUI and then clicks done, all the values get set to booleans.

Steps to reproduce:

  1. Create a list config option where the default value is an empty list.
    Examples:
    ConfigValue<List<? extends Integer>> emptyIntConfig = builder.defineList("empty int list", Arrays.<Integer> asList(), obj -> true);
    ConfigValue<List<? extends String>> emptyStrConfig = builder.defineList("empty string list", new ArrayList<String>(), obj -> true);
  2. Go to the mod config and click Edit on the option you made.
  3. Add a few new values with the Add... button.
  4. Click Done.
  5. Click Edit again.
    -> All the values you added are now just false (unless you typed true).

If you try using the element validator like this...
ConfigValue<List<? extends Integer>> emptyIntConfig = builder.defineList("empty int list validated", Arrays.<Integer> asList(), obj -> obj instanceof Integer);
ConfigValue<List<? extends String>> emptyStrConfig = builder.defineList("empty string list validated", new ArrayList<String>(), obj -> obj instanceof String);
Then you won't be able to add any values at all, no matter what you type. Probably because a Boolean will never be an instance of an Integer or a String, or something like that?

commented

Fixed issue in e8c64d0
As for the config value defined in the steps, refer to my previous reply.

commented

Due to type erasure, Configured does it's best to guess which type it is. For an empty list, it relies on the element validator to determine the type. If you simply return true in the element validator, Configured will assume it's the correct value. It just happens to be that Boolean is the first value tested. Basically ensure you have a strong element validator.

commented

Thanks for responding on Christmas Day!
But as I said in bottom of the first comment, the element validator doesn't exactly work here.
Here are more examples I tried using the element validator:
ConfigValue<List<? extends Integer>> emptyIntConfig1 = builder.defineList("empty int list 1", Arrays.<Integer> asList(), obj -> obj instanceof Integer);
ConfigValue<List<? extends Integer>> emptyIntConfig2 = builder.defineList("empty int list 2", Arrays.asList(), (obj) -> { try { Integer.parseInt(obj.toString()); return true; } catch (NumberFormatException excep) { return false; } });
ConfigValue<List<? extends String>> emptyStrConfig = builder.defineList("empty string list", new ArrayList<String>(), obj -> obj instanceof String);
None of these config options allow me to add values to the lists in the Configured GUI. On the Add... screen, the text I type turns red, and the Done button can't be pressed, no matter what I type.