Skip to content

Commit

Permalink
Updated optconfig API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Aug 8, 2024
1 parent 2d60599 commit ea03915
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import net.lenni0451.optconfig.ConfigContext;
import net.lenni0451.optconfig.access.impl.reflection.ReflectionClassAccess;
import net.lenni0451.optconfig.annotations.*;
import net.lenni0451.optconfig.index.ClassIndexer;
import net.lenni0451.optconfig.index.ConfigType;
Expand Down Expand Up @@ -188,15 +189,15 @@ public void loadFromArguments(final String[] args) throws Exception {

final Map<OptionSpec<Object>, ConfigOption> optionMap = new HashMap<>();
final Stack<SectionIndex> stack = new Stack<>();
stack.push(ClassIndexer.indexClass(ConfigType.INSTANCED, ViaProxyConfig.class));
stack.push(ClassIndexer.indexClass(ConfigType.INSTANCED, ViaProxyConfig.class, ReflectionClassAccess::new));
while (!stack.isEmpty()) {
final SectionIndex index = stack.pop();
stack.addAll(index.getSubSections().values());

for (ConfigOption option : index.getOptions()) {
if (index.getSubSections().containsKey(option)) continue;

Object defaultValue = option.getField().get(this);
Object defaultValue = option.getFieldAccess().getValue(this);
if (option.getTypeSerializer() != null) {
defaultValue = option.createTypeSerializer(null, ViaProxyConfig.class, this).serialize(defaultValue);
}
Expand All @@ -220,12 +221,12 @@ public void loadFromArguments(final String[] args) throws Exception {
if (options.has(entry.getKey())) {
Object value = options.valueOf(entry.getKey());
if (option.getTypeSerializer() != null) {
value = option.createTypeSerializer(null, ViaProxyConfig.class, this).deserialize((Class<Object>) option.getField().getType(), value);
value = option.createTypeSerializer(null, ViaProxyConfig.class, this).deserialize((Class<Object>) option.getFieldAccess().getType(), value);
}
if (option.getValidator() != null) {
value = option.getValidator().invoke(this, value);
}
option.getField().set(this, value);
option.getFieldAccess().setValue(this, value);
}
}

Expand Down

0 comments on commit ea03915

Please sign in to comment.