diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index 3addee6e..6965ffcd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -47,6 +47,7 @@ public class OptionalFile { public int subTreeLevel = 1; @LauncherNetworkAPI public boolean isPreset; + @Deprecated public transient Set dependenciesCount; private volatile transient Collection> watchList = null; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java index 7fa1cf3c..9a248b75 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java @@ -3,11 +3,14 @@ import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.optional.actions.OptionalAction; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; public class OptionalView { public Set enabled = new HashSet<>(); + public Map> dependenciesCountMap = new HashMap<>(); public Set all; @SuppressWarnings("unchecked") @@ -64,8 +67,8 @@ public void enable(OptionalFile file) file.watchEvent(true); if (file.dependencies != null) { for (OptionalFile dep : file.dependencies) { - if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); - dep.dependenciesCount.add(file); + Set dependenciesCount = dependenciesCountMap.computeIfAbsent(dep, k -> new HashSet<>()); + dependenciesCount.add(file); enable(dep); } } @@ -79,22 +82,22 @@ public void disable(OptionalFile file) { if(!enabled.remove(file)) return; file.watchEvent(false); - if (file.dependenciesCount != null) { - for (OptionalFile f : file.dependenciesCount) { + Set dependenciesCount = dependenciesCountMap.get(file); + if (dependenciesCount != null) { + for (OptionalFile f : dependenciesCount) { if (f.isPreset) continue; disable(f); } - file.dependenciesCount.clear(); - file.dependenciesCount = null; + dependenciesCount.clear(); } if (file.dependencies != null) { for (OptionalFile f : file.dependencies) { if (!enabled.contains(f)) continue; - if (f.dependenciesCount == null) { + dependenciesCount = dependenciesCountMap.get(f); + if (dependenciesCount == null) { disable(f); - } else if (f.dependenciesCount.size() <= 1) { - f.dependenciesCount.clear(); - f.dependenciesCount = null; + } else if (dependenciesCount.size() <= 1) { + dependenciesCount.clear(); disable(f); } }