Config watching and config events now actually work!
Also fixed small bug with MOD_CLASSES not defaulting to empty string. Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
7a02ccc3a8
commit
6365674a2a
4 changed files with 17 additions and 9 deletions
|
@ -87,10 +87,11 @@ public abstract class FMLCommonLaunchHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processModClassesEnvironmentVariable(final Map<String, List<Pair<Path, List<Path>>>> arguments) {
|
protected void processModClassesEnvironmentVariable(final Map<String, List<Pair<Path, List<Path>>>> arguments) {
|
||||||
LOGGER.debug(CORE, "Got mod coordinates {} from env", System.getenv("MOD_CLASSES"));
|
final String modClasses = Optional.ofNullable(System.getenv("MOD_CLASSES")).orElse("");
|
||||||
|
LOGGER.debug(CORE, "Got mod coordinates {} from env", modClasses);
|
||||||
|
|
||||||
// "a/b/;c/d/;" -> "modid%%c:\fish\pepper;modid%%c:\fish2\pepper2\;modid2%%c:\fishy\bums;modid2%%c:\hmm"
|
// "a/b/;c/d/;" -> "modid%%c:\fish\pepper;modid%%c:\fish2\pepper2\;modid2%%c:\fishy\bums;modid2%%c:\hmm"
|
||||||
final Map<String, List<Path>> modClassPaths = Arrays.stream(System.getenv("MOD_CLASSES").split(File.pathSeparator)).
|
final Map<String, List<Path>> modClassPaths = Arrays.stream(modClasses.split(File.pathSeparator)).
|
||||||
map(inp -> inp.split("%%", 2)).map(this::buildModPair).
|
map(inp -> inp.split("%%", 2)).map(this::buildModPair).
|
||||||
collect(Collectors.groupingBy(Pair::getLeft, Collectors.mapping(Pair::getRight, Collectors.toList())));
|
collect(Collectors.groupingBy(Pair::getLeft, Collectors.mapping(Pair::getRight, Collectors.toList())));
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,14 @@ public class ConfigFileTypeHandler {
|
||||||
writingMode(WritingMode.REPLACE).
|
writingMode(WritingMode.REPLACE).
|
||||||
build();
|
build();
|
||||||
LOGGER.debug(CONFIG, "Built TOML config for {}", configPath.toString());
|
LOGGER.debug(CONFIG, "Built TOML config for {}", configPath.toString());
|
||||||
|
configData.load();
|
||||||
|
LOGGER.debug(CONFIG, "Loaded TOML config file {}", configPath.toString());
|
||||||
try {
|
try {
|
||||||
FileWatcher.defaultInstance().addWatch(configPath, new ConfigWatcher(c, configData));
|
FileWatcher.defaultInstance().addWatch(configPath, new ConfigWatcher(c, configData, Thread.currentThread().getContextClassLoader()));
|
||||||
LOGGER.debug(CONFIG, "Watching TOML config file {} for changes", configPath.toString());
|
LOGGER.debug(CONFIG, "Watching TOML config file {} for changes", configPath.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Couldn't watch config file", e);
|
throw new RuntimeException("Couldn't watch config file", e);
|
||||||
}
|
}
|
||||||
configData.load();
|
|
||||||
LOGGER.debug(CONFIG, "Loaded TOML config file {}", configPath.toString());
|
|
||||||
return configData;
|
return configData;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,18 @@ public class ConfigFileTypeHandler {
|
||||||
private static class ConfigWatcher implements Runnable {
|
private static class ConfigWatcher implements Runnable {
|
||||||
private final ModConfig modConfig;
|
private final ModConfig modConfig;
|
||||||
private final CommentedFileConfig commentedFileConfig;
|
private final CommentedFileConfig commentedFileConfig;
|
||||||
|
private final ClassLoader realClassLoader;
|
||||||
|
|
||||||
ConfigWatcher(final ModConfig modConfig, final CommentedFileConfig commentedFileConfig) {
|
ConfigWatcher(final ModConfig modConfig, final CommentedFileConfig commentedFileConfig, final ClassLoader classLoader) {
|
||||||
this.modConfig = modConfig;
|
this.modConfig = modConfig;
|
||||||
this.commentedFileConfig = commentedFileConfig;
|
this.commentedFileConfig = commentedFileConfig;
|
||||||
|
this.realClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// Force the regular classloader onto the special thread
|
||||||
|
Thread.currentThread().setContextClassLoader(realClassLoader);
|
||||||
LOGGER.debug(CONFIG, "Config file {} changed, sending notifies", this.modConfig.getFileName());
|
LOGGER.debug(CONFIG, "Config file {} changed, sending notifies", this.modConfig.getFileName());
|
||||||
this.modConfig.fireEvent(new ModConfig.ConfigReloading(this.modConfig));
|
this.modConfig.fireEvent(new ModConfig.ConfigReloading(this.modConfig));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ import org.apache.logging.log4j.Marker;
|
||||||
import org.apache.logging.log4j.MarkerManager;
|
import org.apache.logging.log4j.MarkerManager;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
@ -22,9 +24,9 @@ public class ConfigTracker {
|
||||||
private ConfigTracker() {
|
private ConfigTracker() {
|
||||||
this.fileMap = new ConcurrentHashMap<>();
|
this.fileMap = new ConcurrentHashMap<>();
|
||||||
this.configSets = new EnumMap<>(ModConfig.Type.class);
|
this.configSets = new EnumMap<>(ModConfig.Type.class);
|
||||||
this.configSets.put(ModConfig.Type.CLIENT, new ConcurrentSkipListSet<>());
|
this.configSets.put(ModConfig.Type.CLIENT, Collections.synchronizedSet(new LinkedHashSet<>()));
|
||||||
// this.configSets.put(ModConfig.Type.PLAYER, new ConcurrentSkipListSet<>());
|
// this.configSets.put(ModConfig.Type.PLAYER, new ConcurrentSkipListSet<>());
|
||||||
this.configSets.put(ModConfig.Type.SERVER, new ConcurrentSkipListSet<>());
|
this.configSets.put(ModConfig.Type.SERVER, Collections.synchronizedSet(new LinkedHashSet<>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void trackConfig(final ModConfig config) {
|
void trackConfig(final ModConfig config) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static net.minecraftforge.fml.Logging.LOADING;
|
import static net.minecraftforge.fml.Logging.LOADING;
|
||||||
|
@ -61,7 +62,7 @@ public class FMLModContainer extends ModContainer
|
||||||
triggerMap.put(ModLoadingStage.PROCESS_IMC, dummy().andThen(this::beforeEvent).andThen(this::fireEvent).andThen(this::afterEvent));
|
triggerMap.put(ModLoadingStage.PROCESS_IMC, dummy().andThen(this::beforeEvent).andThen(this::fireEvent).andThen(this::afterEvent));
|
||||||
triggerMap.put(ModLoadingStage.COMPLETE, dummy().andThen(this::beforeEvent).andThen(this::completeLoading).andThen(this::fireEvent).andThen(this::afterEvent));
|
triggerMap.put(ModLoadingStage.COMPLETE, dummy().andThen(this::beforeEvent).andThen(this::completeLoading).andThen(this::fireEvent).andThen(this::afterEvent));
|
||||||
this.eventBus = IEventBus.create(this::onEventFailed);
|
this.eventBus = IEventBus.create(this::onEventFailed);
|
||||||
|
this.configHandler = Optional.of(event -> this.eventBus.post(event));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
modClass = Class.forName(className, true, modClassLoader);
|
modClass = Class.forName(className, true, modClassLoader);
|
||||||
|
|
Loading…
Reference in a new issue