Skip to content

Commit

Permalink
Remove required parameter to Config annotation (#34)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Caedis and github-actions[bot] authored Feb 27, 2024
1 parent f6cfa5c commit 7be106d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/gtnewhorizon/gtnhlib/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
});
}
}

0 comments on commit 7be106d

Please sign in to comment.