|
2 | 2 |
|
3 | 3 | import com.falsepattern.lib.StableAPI;
|
4 | 4 | import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
| 5 | +import com.falsepattern.lib.internal.FalsePatternLib; |
5 | 6 | import cpw.mods.fml.client.event.ConfigChangedEvent;
|
6 | 7 | import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
7 | 8 | import lombok.*;
|
@@ -118,7 +119,21 @@ private static void processConfig(Class<?> configClass) throws IllegalAccessExce
|
118 | 119 | .map(ConfigurationManager::extractValue)
|
119 | 120 | .orElse(field.get(null));
|
120 | 121 | val possibleValues = enumValues.stream().map(Enum::name).toArray(String[]::new);
|
121 |
| - field.set(null, fieldClass.getDeclaredField(rawConfig.getString(name, category, defaultValue.name(), comment, possibleValues, langKey)).get(null)); |
| 122 | + var value = rawConfig.getString(name, category, defaultValue.name(), comment + "\nPossible values: " + Arrays.toString(possibleValues) + "\n", possibleValues, langKey); |
| 123 | + |
| 124 | + try { |
| 125 | + if (!Arrays.asList(possibleValues).contains(value)) { |
| 126 | + throw new NoSuchFieldException(); |
| 127 | + } |
| 128 | + val enumField = fieldClass.getDeclaredField(value); |
| 129 | + if (!enumField.isEnumConstant()) { |
| 130 | + throw new NoSuchFieldException(); |
| 131 | + } |
| 132 | + field.set(null, enumField.get(null)); |
| 133 | + } catch (NoSuchFieldException e) { |
| 134 | + FalsePatternLib.getLog().warn("Invalid value " + value + " for enum configuration field " + field.getName() + " of type " + fieldClass.getName() + " in config class " + configClass.getName() + "! Using default value of " + defaultValue + "!"); |
| 135 | + field.set(null, defaultValue); |
| 136 | + } |
122 | 137 | } else {
|
123 | 138 | throw new ConfigException("Illegal config field: " + field.getName() + " in " + configClass.getName() + ": Unsupported type " + fieldClass.getName() + "! Did you forget an @Ignore annotation?");
|
124 | 139 | }
|
|
0 commit comments