Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyfts committed Sep 14, 2024
1 parent 9dbb1d1 commit dce830c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public void load(@Nullable Object instance, @Nullable String defValueString, Fie
stringValues[i] = Double.toString(defaultValue[i]);
}
comment = comment + " [default: " + Arrays.toString(stringValues) + "]";
double[] value = config.get(category, name, defaultValue, comment).getDoubleList();
double[] value = config.get(category, name, defaultValue, comment).setLanguageKey(langKey).getDoubleList();

field.set(instance, value);
}
Expand Down Expand Up @@ -484,7 +484,7 @@ public void load(@Nullable Object instance, @Nullable String defValueString, Fie
stringValues[i] = Integer.toString(defaultValue[i]);
}
comment = comment + " [default: " + Arrays.toString(stringValues) + "]";
int[] value = config.get(category, name, defaultValue, comment).getIntList();
int[] value = config.get(category, name, defaultValue, comment).setLanguageKey(langKey).getIntList();

field.set(instance, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void registerConfig(Class<?> configClass) throws ConfigException {
init();
val cfg = Optional.ofNullable(configClass.getAnnotation(Config.class)).orElseThrow(
() -> new ConfigException("Class " + configClass.getName() + " does not have a @Config annotation!"));
val category = cfg.category().trim();
val category = cfg.category().trim().toLowerCase();
val modid = cfg.modid();
val filename = Optional.of(cfg.filename().trim()).filter(s -> !s.isEmpty()).orElse(modid);

Expand Down Expand Up @@ -93,7 +93,7 @@ public static void save(Class<?>... configClasses) {
try {
val cfg = Optional.ofNullable(clazz.getAnnotation(Config.class)).orElseThrow(
() -> new ConfigException("Class " + clazz.getName() + " does not have a @Config annotation!"));
val category = cfg.category().trim();
val category = cfg.category().trim().toLowerCase();
Configuration rawConfig = configs.get(getConfigKey(cfg));
save(clazz, null, rawConfig, category);
savedConfigs.add(rawConfig);
Expand Down Expand Up @@ -221,7 +221,7 @@ private static void processConfigInternal(Class<?> configClass, String category,
}

if (category.isEmpty()) return;
if (cat.getLanguagekey().equals(cat.getName())) {
if (cat.getLanguagekey().equals(category)) {
val langKey = getLangKey(configClass, configClass.getAnnotation(Config.LangKey.class), null, cat);
cat.setLanguageKey(langKey);
}
Expand Down Expand Up @@ -259,7 +259,9 @@ public static List<IConfigElement> getConfigElements(Class<?> configClass, boole
() -> new ConfigException("Class " + configClass.getName() + " does not have a @Config annotation!"));
val rawConfig = Optional.ofNullable(configs.get(getConfigKey(cfg))).map(
(conf) -> Optional.ofNullable(configToCategoryClassMap.get(conf))
.map((map) -> map.get(cfg.category().trim()).contains(configClass)).orElse(false) ? conf : null)
.map((map) -> map.get(cfg.category().trim().toLowerCase()).contains(configClass)).orElse(false)
? conf
: null)
.orElseThrow(
() -> new ConfigException("Tried to get config elements for non-registered config class!"));

Expand Down Expand Up @@ -352,7 +354,7 @@ private static String getLangKey(Class<?> configClass, @Nullable Config.LangKey
if (langKey != null) return langKey.value();

Config.LangKeyPattern pattern = getClassOrBaseAnnotation(configClass, Config.LangKeyPattern.class);
String name = Optional.ofNullable(fieldName).orElse(category.getName());
String name = Optional.ofNullable(fieldName).orElse(category.getQualifiedName());
if (pattern == null) return name;
String patternStr = pattern.pattern();

Expand Down Expand Up @@ -405,13 +407,13 @@ private static String buildKeyFromPattern(String pattern, String modId, String f
private static @Nullable <A extends Annotation> A getClassOrBaseAnnotation(Class<?> clazz,
Class<A> annotationClass) {
A annotation = clazz.getAnnotation(annotationClass);
if (annotation != null || !clazz.isMemberClass()) return annotation;

while (clazz.isMemberClass()) {
while (annotation == null && clazz.isMemberClass()) {
clazz = clazz.getDeclaringClass();
annotation = clazz.getAnnotation(annotationClass);
}

return clazz.getAnnotation(annotationClass);
return annotation;
}

private static boolean isFieldSubCategory(@Nullable Field field) {
Expand Down

0 comments on commit dce830c

Please sign in to comment.