Remove required parameter to Config annotation (#34)

* dont make them required

* Remove unused saving code

* Spotless apply for branch configFileOverride for #34 (#35)

Co-authored-by: GitHub GTNH Actions <>

* This was actually needed

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
CaedisGitHub GTNH Actionsgithub-actions[bot]
authored and GitHub committed 2024-02-27 09:29:40 +00:00
1 parent f6cfa5c935
commit 7be106da73
2 files changed
+7 -43

No files matched your search

@@ -25,12 +25,12 @@ public @interface Config {
* The subdirectory of the config directory to use. Defaults to none (config/). If you want to use a subdirectory,
* you must specify it as a relative path (e.g. "myMod").
*/
String configSubDirectory();
String configSubDirectory() default "";
/**
* The name of the configuration file. Defaults to the modid. The file extension (.cfg) is added automatically.
*/
String filename();
String filename() default "";
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.TYPE })
@@ -24,9 +24,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.client.config.IConfigElement;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
@@ -62,14 +59,14 @@ public class ConfigurationManager {
() -> new ConfigException("Config class " + configClass.getName() + " has an empty category!"));
val rawConfig = configs.computeIfAbsent(cfg.modid(), (ignored) -> {
Path newConfigDir = configDir;
if (cfg.configSubDirectory() != null) {
newConfigDir = newConfigDir.resolve(cfg.configSubDirectory());
if (!cfg.configSubDirectory().trim().isEmpty()) {
newConfigDir = newConfigDir.resolve(cfg.configSubDirectory().trim());
}
String fileName;
if (cfg.filename() != null) {
fileName = cfg.filename();
} else {
if (cfg.filename().trim().isEmpty()) {
fileName = cfg.modid();
} else {
fileName = cfg.filename().trim();
}
val c = new Configuration(newConfigDir.resolve(fileName + ".cfg").toFile());
c.load();
@@ -255,37 +252,4 @@ public class ConfigurationManager {
configDir = minecraftHome().toPath().resolve("config");
initialized = true;
}
/**
* Internal, do not use.
*/
public static void registerBus() {
FMLCommonHandler.instance().bus().register(instance);
}
/**
* Internal, do not use.
*
* @param event The event.
*/
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
init();
val config = configs.get(event.modID);
if (config == null) {
return;
}
val configClasses = configToClassMap.get(config);
configClasses.forEach((configClass) -> {
try {
val category = Optional.ofNullable(configClass.getAnnotation(Config.class)).map(Config::category)
.orElseThrow(
() -> new ConfigException(
"Failed to get config category for class " + configClass.getName()));
processConfigInternal(configClass, category, config);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}