Skip to content

Commit

Permalink
Remove unnecessary IConfigEvent and ConfigConfig (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Jun 16, 2024
1 parent 7c486f8 commit 2c95019
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 64 deletions.
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 java.util.ServiceLoader;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.config.IConfigEvent;
import net.neoforged.fml.loading.FMLLoader;
import org.jetbrains.annotations.ApiStatus;

Expand All @@ -27,8 +26,4 @@ public class Bindings {
public static IEventBus getGameBus() {
return provider.getGameBus();
}

public static IConfigEvent.ConfigConfig getConfigConfiguration() {
return provider.getConfigConfiguration();
}
}
3 changes: 0 additions & 3 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,9 @@
package net.neoforged.fml;

import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.config.IConfigEvent;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public interface IBindingsProvider {
IEventBus getGameBus();

IConfigEvent.ConfigConfig getConfigConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Function;
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 @@ -148,7 +149,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 @@ -17,6 +17,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.neoforged.fml.event.config.ModConfigEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void openConfig(final ModConfig config, final Path configBasePath, @Nulla
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 @@ -92,9 +93,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 @@ -105,7 +104,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
46 changes: 0 additions & 46 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 @@ -11,7 +11,9 @@
import java.io.ByteArrayInputStream;
import java.nio.file.Path;
import java.util.Locale;
import java.util.function.Function;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.fml.loading.StringUtils;

public class ModConfig {
Expand Down Expand Up @@ -74,7 +76,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, ModConfigEvent> constructor) {
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

0 comments on commit 2c95019

Please sign in to comment.