mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-26 14:53:14 +00:00
Add filename and subdirectory overrides to Config class annotation (#33)
* Add filename and subdirectory overrides * spotless * Fix nit * Nother nit
This commit is contained in:
1 parent
389101eb7b
commit
f6cfa5c935
2 files changed
+22
-1
No files matched your search
@@ -21,6 +21,17 @@ public @interface Config {
|
||||
*/
|
||||
String category() default "general";
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* The name of the configuration file. Defaults to the modid. The file extension (.cfg) is added automatically.
|
||||
*/
|
||||
String filename();
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.FIELD, ElementType.TYPE })
|
||||
@interface LangKey {
|
||||
|
||||
@@ -61,7 +61,17 @@ public class ConfigurationManager {
|
||||
val category = Optional.of(cfg.category().trim()).map((cat) -> cat.length() == 0 ? null : cat).orElseThrow(
|
||||
() -> new ConfigException("Config class " + configClass.getName() + " has an empty category!"));
|
||||
val rawConfig = configs.computeIfAbsent(cfg.modid(), (ignored) -> {
|
||||
val c = new Configuration(configDir.resolve(cfg.modid() + ".cfg").toFile());
|
||||
Path newConfigDir = configDir;
|
||||
if (cfg.configSubDirectory() != null) {
|
||||
newConfigDir = newConfigDir.resolve(cfg.configSubDirectory());
|
||||
}
|
||||
String fileName;
|
||||
if (cfg.filename() != null) {
|
||||
fileName = cfg.filename();
|
||||
} else {
|
||||
fileName = cfg.modid();
|
||||
}
|
||||
val c = new Configuration(newConfigDir.resolve(fileName + ".cfg").toFile());
|
||||
c.load();
|
||||
return c;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user