fix: profile loading - check configuration to see if options to load are changed

worded horribly but just know it fixes annoyances
This commit is contained in:
trafficlunar 2024-12-10 20:02:25 +00:00
parent 60a2bcb853
commit 96c4d8eac8

View file

@ -12,6 +12,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.stream.Stream;
@ -145,6 +146,7 @@ public class Profiles {
public static boolean isProfileLoaded(String profileName) {
Path profile = PROFILES_DIRECTORY.resolve(profileName);
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
List<Path> optionFiles = new ArrayList<>();
optionFiles.add(OPTIONS_FILE);
@ -159,10 +161,34 @@ public class Profiles {
try {
for (Path optionFile : optionFiles) {
Path profileOptions = profile.resolve(optionFile.getFileName());
if (optionFile.getFileName().equals(OPTIONS_FILE)) {
try (Stream<String> lines = Files.lines(optionFile)) {
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
AtomicBoolean loaded = new AtomicBoolean(false);
lines.forEach((line) -> {
String[] option = line.split(":");
if (optionsToLoad.contains(option[0])) {
try (Stream<String> profileLines = Files.lines(profileOptions)) {
loaded.set(profileLines.anyMatch(profileLine -> profileLine.equals(line)));
} catch (IOException e) {
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when checking each line in options.txt if the profiles is loaded", profileName, e);
}
}
});
return loaded.get();
} catch (IOException e) {
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when opening options.txt to check if the profile is loaded", profileName, e);
}
} else {
if (!FileUtils.contentEquals(optionFile.toFile(), profileOptions.toFile())) {
return false;
}
}
}
} catch (IOException e) {
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when checking if the profile is loaded", profileName, e);
return false;