config: Add forceDefault option

This commit is contained in:
Oliver
2025-07-19 19:21:54 +02:00
parent 19036ae0bc
commit 5f047bbf70
3 changed files with 18 additions and 5 deletions

View File

@@ -45,12 +45,16 @@ public class Config {
*/
public <T> T get(String path) {
ConfigField<?> field = fields.get(path);
if (field != null) {
Object value = values.computeIfAbsent(path, k -> field.defaultValue());
return (T) field.type().cast(value);
if (field == null) {
return null;
}
return null;
if (field.forceDefault()) {
return (T) field.defaultValue();
}
Object value = values.computeIfAbsent(path, k -> field.defaultValue());
return (T) field.type().cast(value);
}
/**

View File

@@ -8,6 +8,7 @@ package com.fancyinnovations.config;
* @param description a description of the field
* @param forRemoval indicates if this field should be removed
* @param defaultValue the default value of the field
* @param forceDefault indicates if the default value should be enforced
* @param type the class type of the field value
*/
public record ConfigField<T>(
@@ -15,6 +16,7 @@ public record ConfigField<T>(
String description,
boolean forRemoval,
T defaultValue,
boolean forceDefault,
Class<T> type
) {
}