From 00b7d6dfc64476f6af62d06c417dafeba2ed6f97 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Wed, 27 Sep 2023 00:03:36 +0200 Subject: [PATCH] Fix settings being saved during startup. (#1636) --- .../se/llbit/chunky/map/WorldMapLoader.java | 2 +- .../se/llbit/chunky/PersistentSettings.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java b/chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java index 30b8c6359a..6516914f5c 100644 --- a/chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java +++ b/chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java @@ -80,7 +80,7 @@ public void loadWorld(File worldDir) { updateRegionChangeWatcher(newWorld.currentDimension()); File newWorldDir = world.getWorldDirectory(); - if (newWorldDir != null) { + if (newWorldDir != null && !newWorldDir.equals(PersistentSettings.getLastWorld())) { PersistentSettings.setLastWorld(newWorldDir); } } diff --git a/lib/src/se/llbit/chunky/PersistentSettings.java b/lib/src/se/llbit/chunky/PersistentSettings.java index 1f38e64a0f..547ebe2556 100644 --- a/lib/src/se/llbit/chunky/PersistentSettings.java +++ b/lib/src/se/llbit/chunky/PersistentSettings.java @@ -109,10 +109,12 @@ private static void load() { private static void migrateOldSettings() { String lastTexturePack = settings.getString("lastTexturePack", null); - if(lastTexturePack != null) { - setLastTexturePack(lastTexturePack); + if (lastTexturePack != null) { + setEnabledResourcePacks( + parseResourcePackPaths(lastTexturePack).toArray(new File[0]), false + ); // TODO: Remove legacy setting in 2.6.0 -// settings.removeSetting("lastTexturePack"); + // settings.removeSetting("lastTexturePack"); } } @@ -207,7 +209,6 @@ public static void setLastTexturePack(String path) { setEnabledResourcePacks( parseResourcePackPaths(path).toArray(new File[0]) ); - save(); } /** @@ -244,14 +245,20 @@ public static List parseResourcePackPaths(Stream paths) { } public static void setEnabledResourcePacks(File... enabledTexturePacks) { + setEnabledResourcePacks(enabledTexturePacks, true); + } + + private static void setEnabledResourcePacks(File[] enabledTexturePacks, boolean save) { JsonArray array = new JsonArray(enabledTexturePacks.length); - for(File texturePackFile : enabledTexturePacks) { + for (File texturePackFile : enabledTexturePacks) { array.add(texturePackFile.toString()); } settings.set("enabledResourcePacks", array); // TODO: Remove legacy setting in 2.6.0 settings.setString("lastTexturePack", getLastTexturePack()); - save(); + if (save) { + PersistentSettings.save(); + } } public static List getEnabledResourcePacks() {