From 982820ecbdeb849bc751a4e432718bd6fe295c26 Mon Sep 17 00:00:00 2001 From: Nolij Date: Tue, 29 Oct 2024 17:03:36 -0400 Subject: [PATCH] fix #24 --- CHANGELOG.md | 3 +- .../zume/impl/config/ZumeConfigImpl.java | 31 ++++++------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c50ce01..955760a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/api/src/main/java/dev/nolij/zume/impl/config/ZumeConfigImpl.java b/api/src/main/java/dev/nolij/zume/impl/config/ZumeConfigImpl.java index ec05cdc..1bc7b13 100644 --- a/api/src/main/java/dev/nolij/zume/impl/config/ZumeConfigImpl.java +++ b/api/src/main/java/dev/nolij/zume/impl/config/ZumeConfigImpl.java @@ -147,6 +147,7 @@ private void writeToFile(final File configFile) { Files.createDirectories(configFolder); } catch (IOException e) { Zume.LOGGER.error("Failed to create config folder: ", e); + return; } } @@ -154,29 +155,22 @@ private void writeToFile(final File 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 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(); } } @@ -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); } } }