[FIX] Bug with missing forgotten dependency/conflict

This commit is contained in:
Sevastjan 2023-07-12 01:48:16 +03:00
parent ca87e0c726
commit aed383b1fb
No known key found for this signature in database
GPG key ID: A18133AD7A67B8AB
2 changed files with 34 additions and 3 deletions

View file

@ -375,9 +375,10 @@ public void verify() {
if (s == null)
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name));
}
if(f.xorConflictFile != null) for (OptionalDepend s : f.xorConflictFile) {
if (s == null)
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.xorConflictFile", f.name));
if(f.xorConflictFile != null)
for (OptionalDepend s : f.xorConflictFile) {
if (s == null)
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.xorConflictFile", f.name));
}
if (f.triggersList != null) {
for (OptionalTrigger trigger : f.triggersList) {

View file

@ -9,6 +9,7 @@
import java.util.Set;
import java.util.Arrays;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
public class OptionalView {
public Set<OptionalFile> enabled = new HashSet<>();
@ -26,6 +27,7 @@ public OptionalView(OptionalView view) {
this.enabled = new HashSet<>(view.enabled);
this.installInfo = new HashMap<>(view.installInfo);
this.all = view.all;
fixDependencies();
}
public OptionalView(ClientProfile profile, OptionalView old) {
@ -41,6 +43,7 @@ public OptionalView(ClientProfile profile, OptionalView old) {
disable(newFile, (file, status) -> {});
}
}
fixDependencies();
}
@SuppressWarnings("unchecked")
@ -81,6 +84,33 @@ public Set<OptionalAction> getEnabledActions() {
return results;
}
//Needed if dependency/conflict was added after mod declaring it and clients have their profiles with this mod enabled
public void fixDependencies() {
Set<OptionalFile> disabled = all.stream().filter(t -> !isEnabled(t)).collect(Collectors.toSet());
for (OptionalFile file : disabled) {
if (file.xorConflict != null && Arrays.stream(file.xorConflict).noneMatch(this::isEnabled)) {
enable(file.xorConflict[0], false, null);
}
}
for (OptionalFile file : enabled) {
if (file.dependencies != null) {
for (OptionalFile dep : file.dependencies) {
enable(dep, false, null);
}
}
if (file.conflict != null) {
for (OptionalFile conflict : file.conflict) {
disable(conflict, null);
}
}
if (file.xorConflict != null) {
for (OptionalFile xorConflict : file.xorConflict) {
disable(xorConflict, null);
}
}
}
}
public Set<OptionalAction> getDisabledActions() {
Set<OptionalAction> results = new HashSet<>();
for (OptionalFile e : all) {