diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/config/Config.java b/src/main/java/com/gtnewhorizon/gtnhlib/config/Config.java index b659f8f..8f4dd19 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/config/Config.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/config/Config.java @@ -25,12 +25,12 @@ * 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 }) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/config/ConfigurationManager.java b/src/main/java/com/gtnewhorizon/gtnhlib/config/ConfigurationManager.java index 3c183b5..c6c3e23 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/config/ConfigurationManager.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/config/ConfigurationManager.java @@ -24,9 +24,6 @@ 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 static void registerConfig(Class configClass) throws ConfigException { () -> 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 @@ private static void init() { 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(); - } - }); - } }