Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copied from NeoForge's ModConfig.Type to be aligned with it.
* @author rubensworks
*/
// TODO: in next major, rename COMMON to LOCAL and SERVER to SYNCED to match NeoForge's ModConfig.Type

Check warning on line 7 in loader-common/src/main/java/org/cyclops/cyclopscore/config/ModConfigLocation.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=CyclopsMC_CyclopsCore&issues=AaECOJ4OQEO5fzLFCHJ4&open=AaECOJ4OQEO5fzLFCHJ4&pullRequest=252
public enum ModConfigLocation {
/**
* Common mod config for configuration that needs to be loaded on both environments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public ConfigHandlerFabricHandler(ConfigHandlerFabric configHandler) {

public void onLoad(ModConfig configEvent) {
this.configHandler.getMod().log(Level.TRACE, "Load config");
syncProcessedConfigs(false);
syncProcessedConfigs(configEvent, false);
}

public void onReload(ModConfig configEvent) {
this.configHandler.getMod().log(Level.TRACE, "Reload config");
syncProcessedConfigs(true);
syncProcessedConfigs(configEvent, true);
}

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public void initialize(Collection<IConfigInitializer> configInitializers) {
configBuilders.put(modConfigLocationToType(configProperty.getConfigLocation()), configBuilderProperty);
}
this.configHandler.getCategories().add(configProperty.getCategory());
this.onConfigPropertyInit(configProperty, configBuilder);
this.onConfigPropertyInit(configProperty, configBuilderProperty);
if (configProperty.isCommandable()) {
this.configHandler.getCommandableProperties().put(configProperty.getName(), configProperty);
}
Expand Down Expand Up @@ -102,13 +102,18 @@ protected <T> void onConfigPropertyInit(ConfigurablePropertyData<T> configProper
/**
* Sync the config values that were already loaded.
* This will update the values in-game and in the config file.
* @param config The mod config that is being loaded.
* @param reload If we are reloading, otherwise this is an initial load.
*/
@SuppressWarnings("unchecked")
public void syncProcessedConfigs(boolean reload) {
public void syncProcessedConfigs(ModConfig config, boolean reload) {
for(ExtendedConfigCommon<?, ?, ?> eConfig : this.configHandler.getConfigurables()) {
// Re-save additional properties
for(ConfigurablePropertyData configProperty : eConfig.configProperties.values()) {
// Only properties of the loaded config have values, others would throw.
if (modConfigLocationToType(configProperty.getConfigLocation()) != config.getType()) {
continue;
}
configProperty.saveToField();
eConfig.onConfigPropertyReload(configProperty, reload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void initialize(Collection<IConfigInitializer> configInitializers) {
configBuilders.put(modConfigLocationToType(configProperty.getConfigLocation()), configBuilderProperty);
}
getCategories().add(configProperty.getCategory());
this.onConfigPropertyInit(configProperty, configBuilder);
this.onConfigPropertyInit(configProperty, configBuilderProperty);
if (configProperty.isCommandable()) {
getCommandableProperties().put(configProperty.getName(), configProperty);
}
Expand Down Expand Up @@ -159,6 +159,10 @@ public void syncProcessedConfigs(ModConfig config, boolean reload) {
for(ExtendedConfigCommon<?, ?, ?> eConfig : this.getConfigurables()) {
// Re-save additional properties
for(ConfigurablePropertyData configProperty : eConfig.configProperties.values()) {
// Only properties of the loaded config have values, others would throw.
if (modConfigLocationToType(configProperty.getConfigLocation()) != config.getType()) {
continue;
}
configProperty.saveToField();
eConfig.onConfigPropertyReload(configProperty, reload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void initialize(Collection<IConfigInitializer> configInitializers) {
configBuilders.put(modConfigLocationToType(configProperty.getConfigLocation()), configBuilderProperty);
}
getCategories().add(configProperty.getCategory());
this.onConfigPropertyInit(configProperty, configBuilder);
this.onConfigPropertyInit(configProperty, configBuilderProperty);
if (configProperty.isCommandable()) {
getCommandableProperties().put(configProperty.getName(), configProperty);
}
Expand Down Expand Up @@ -160,6 +160,10 @@ public void syncProcessedConfigs(ModConfig config, boolean reload) {
for(ExtendedConfigCommon<?, ?, ?> eConfig : this.getConfigurables()) {
// Re-save additional properties
for(ConfigurablePropertyData configProperty : eConfig.configProperties.values()) {
// Only properties of the loaded config have values, others would throw.
if (modConfigLocationToType(configProperty.getConfigLocation()) != config.getType()) {
continue;
}
configProperty.saveToField();
eConfig.onConfigPropertyReload(configProperty, reload);
}
Expand Down
Loading