Skip to content

Commit

Permalink
Fix settings being saved during startup. (chunky-dev#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik authored Sep 26, 2023
1 parent 57bc68e commit 00b7d6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
19 changes: 13 additions & 6 deletions lib/src/se/llbit/chunky/PersistentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -207,7 +209,6 @@ public static void setLastTexturePack(String path) {
setEnabledResourcePacks(
parseResourcePackPaths(path).toArray(new File[0])
);
save();
}

/**
Expand Down Expand Up @@ -244,14 +245,20 @@ public static List<File> parseResourcePackPaths(Stream<String> 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<File> getEnabledResourcePacks() {
Expand Down

0 comments on commit 00b7d6d

Please sign in to comment.