Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify config event posting logic (remove ConfigConfig) #76

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 0 additions & 5 deletions loader/src/main/java/net/neoforged/fml/Bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import cpw.mods.modlauncher.util.ServiceLoaderUtils;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.config.IConfigEvent;
import net.neoforged.fml.loading.FMLLoader;

import java.util.ServiceLoader;
Expand All @@ -33,8 +32,4 @@ public static Supplier<IEventBus> getForgeBus() {
public static Supplier<I18NParser> getMessageParser() {
return INSTANCE.provider.getMessageParser();
}

public static Supplier<IConfigEvent.ConfigConfig> getConfigConfiguration() {
return INSTANCE.provider.getConfigConfiguration();
}
}
2 changes: 0 additions & 2 deletions loader/src/main/java/net/neoforged/fml/IBindingsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
package net.neoforged.fml;

import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.config.IConfigEvent;

import java.util.function.Supplier;

public interface IBindingsProvider {
Supplier<IEventBus> getForgeBusSupplier();
Supplier<I18NParser> getMessageParser();
Supplier<IConfigEvent.ConfigConfig> getConfigConfiguration();
}
2 changes: 1 addition & 1 deletion loader/src/main/java/net/neoforged/fml/ModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void addConfig(final ModConfig modConfig) {
* Accept an arbitrary event for processing by the mod. Posted to {@link #getEventBus()}.
* @param e Event to accept
*/
protected final <T extends Event & IModBusEvent> void acceptEvent(T e) {
public final <T extends Event & IModBusEvent> void acceptEvent(T e) {
IEventBus bus = getEventBus();
if (bus == null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.electronwill.nightconfig.core.io.ParsingException;
import com.electronwill.nightconfig.core.io.WritingMode;
import com.mojang.logging.LogUtils;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.loading.FMLConfig;
import net.neoforged.fml.loading.FMLPaths;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -167,7 +168,7 @@ public void run() {
}
LOGGER.debug(CONFIG, "Config file {} changed, sending notifies", this.modConfig.getFileName());
this.modConfig.getSpec().afterReload();
IConfigEvent.reloading(this.modConfig).post();
this.modConfig.postConfigEvent(ModConfigEvent.Reloading::new);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.mojang.logging.LogUtils;
import java.nio.file.Files;
import net.neoforged.fml.event.config.ModConfigEvent;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.Marker;
Expand Down Expand Up @@ -77,7 +78,7 @@ private void openConfig(final ModConfig config, final Path configBasePath, @Null
final Path basePath = resolveBasePath(config, configBasePath, configOverrideBasePath);
final CommentedFileConfig configData = ConfigFileTypeHandler.TOML.reader(basePath).apply(config);
config.setConfigData(configData);
IConfigEvent.loading(config).post();
config.postConfigEvent(ModConfigEvent.Loading::new);
config.save();
}

Expand All @@ -86,9 +87,7 @@ private void closeConfig(final ModConfig config) {
LOGGER.trace(CONFIG, "Closing config file type {} at {} for {}", config.getType(), config.getFileName(), config.getModId());
// stop the filewatcher before we save the file and close it, so reload doesn't fire
ConfigFileTypeHandler.TOML.unload(config);
var unloading = IConfigEvent.unloading(config);
if (unloading != null)
unloading.post();
config.postConfigEvent(ModConfigEvent.Unloading::new);
config.save();
config.setConfigData(null);
}
Expand All @@ -99,7 +98,7 @@ public void loadDefaultServerConfigs() {
final CommentedConfig commentedConfig = CommentedConfig.inMemory();
modConfig.getSpec().correct(commentedConfig);
modConfig.setConfigData(commentedConfig);
IConfigEvent.loading(modConfig).post();
modConfig.postConfigEvent(ModConfigEvent.Loading::new);
});
}

Expand Down
44 changes: 0 additions & 44 deletions loader/src/main/java/net/neoforged/fml/config/IConfigEvent.java

This file was deleted.

8 changes: 7 additions & 1 deletion loader/src/main/java/net/neoforged/fml/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import com.electronwill.nightconfig.core.file.FileConfig;
import com.electronwill.nightconfig.toml.TomlFormat;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.loading.StringUtils;

import java.io.ByteArrayInputStream;
import java.nio.file.Path;
import java.util.Locale;
import java.util.function.Function;

public class ModConfig
{
Expand Down Expand Up @@ -76,7 +78,11 @@ public Path getFullPath() {

public void acceptSyncedConfig(byte[] bytes) {
setConfigData(TomlFormat.instance().createParser().parse(new ByteArrayInputStream(bytes)));
IConfigEvent.reloading(this).post();
postConfigEvent(ModConfigEvent.Reloading::new);
}

void postConfigEvent(Function<ModConfig, ? extends ModConfigEvent> constructor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest making this synchronized for now as a stop-gap to prevent Loading and Reloading from firing concurrently. (Unless we have fixed that problem already.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see the problem, and I have an idea to fix it. I'd like to leave it for another PR though.

container.acceptEvent(constructor.apply(this));
}

public enum Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
package net.neoforged.fml.event.config;

import net.neoforged.bus.api.Event;
import net.neoforged.fml.config.IConfigEvent;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.IModBusEvent;

public class ModConfigEvent extends Event implements IModBusEvent, IConfigEvent {
public class ModConfigEvent extends Event implements IModBusEvent {
private final ModConfig config;

ModConfigEvent(final ModConfig config) {
this.config = config;
}

@Override
public ModConfig getConfig() {
return config;
}
Expand Down
Loading