Skip to content

Commit

Permalink
fix #24
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolij committed Oct 29, 2024
1 parent 63d165f commit 982820e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
- fix NeoForge 21.2+
- fix global config folder being created even if override or instance config is used
- fix config bug
- further improvements to overall system stability and other minor adjustments have been made to enhance the user experience
31 changes: 10 additions & 21 deletions api/src/main/java/dev/nolij/zume/impl/config/ZumeConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,36 +147,30 @@ private void writeToFile(final File configFile) {
Files.createDirectories(configFolder);
} catch (IOException e) {
Zume.LOGGER.error("Failed to create config folder: ", e);
return;
}
}

try (final FileWriter configWriter = new FileWriter(configFile)) {
ZSON.write(Zson.obj2Map(this), configWriter);
configWriter.flush();
} catch (IOException e) {
throw new RuntimeException("Failed to write config file", e);
Zume.LOGGER.error("Failed to write config file", e);
}
}

private static Consumer<ZumeConfigImpl> consumer;
private static IFileWatcher instanceWatcher;
private static IFileWatcher globalWatcher;
private static IFileWatcher configWatcher;
private static File instanceFile = null;
private static File globalFile = null;

public static void replace(final ZumeConfigImpl newConfig) throws InterruptedException {
try {
instanceWatcher.lock();
try {
globalWatcher.lock();

newConfig.writeToFile(getConfigFile());
consumer.accept(newConfig);
} finally {
globalWatcher.unlock();
}
configWatcher.lock();
newConfig.writeToFile(getConfigFile());
consumer.accept(newConfig);
} finally {
instanceWatcher.unlock();
configWatcher.unlock();
}
}

Expand Down Expand Up @@ -235,17 +229,12 @@ public static void init(final Path instanceConfigPath, final String fileName, fi
final IFileWatcher nullWatcher = new NullFileWatcher();

if (config.disable) {
instanceWatcher = nullWatcher;
globalWatcher = nullWatcher;
} else if (CONFIG_PATH_OVERRIDE == null) {
instanceWatcher = FileWatcher.onFileChange(instanceFile.toPath(), ZumeConfigImpl::reloadConfig);
globalWatcher = FileWatcher.onFileChange(globalFile.toPath(), ZumeConfigImpl::reloadConfig);
configWatcher = nullWatcher;
} else {
instanceWatcher = nullWatcher;
globalWatcher = FileWatcher.onFileChange(getConfigFile().toPath(), ZumeConfigImpl::reloadConfig);
configWatcher = FileWatcher.onFileChange(getConfigFile().toPath(), ZumeConfigImpl::reloadConfig);
}
} catch (IOException e) {
throw new RuntimeException("Failed to create file watcher", e);
Zume.LOGGER.error("Failed to create file watcher", e);
}
}
}

0 comments on commit 982820e

Please sign in to comment.