Add a better license error screen (#7350)

This commit is contained in:
ichttt 2020-09-23 23:16:36 +02:00 committed by GitHub
parent 0484f695fb
commit e344fd08a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 4 deletions

View file

@ -19,6 +19,8 @@
package net.minecraftforge.fml.loading;
import net.minecraftforge.forgespi.language.IModInfo;
import java.util.List;
/**
@ -29,10 +31,17 @@ public class EarlyLoadingException extends RuntimeException {
public static class ExceptionData {
private final IModInfo modInfo;
private final String i18message;
private final Object[] args;
public ExceptionData(final String message, Object... args) {
this(message, null, args);
}
public ExceptionData(final String message, final IModInfo modInfo, Object... args) {
this.i18message = message;
this.modInfo = modInfo;
this.args = args;
}
@ -43,6 +52,10 @@ public class EarlyLoadingException extends RuntimeException {
public Object[] getArgs() {
return args;
}
public IModInfo getModInfo() {
return modInfo;
}
}
private final List<ExceptionData> errorMessages;

View file

@ -42,6 +42,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
@ -191,7 +192,7 @@ public class ModSorter
if (!dupedMods.isEmpty()) {
final List<EarlyLoadingException.ExceptionData> duplicateModErrors = dupedMods
.stream()
.map(dm -> new EarlyLoadingException.ExceptionData("fml.modloading.dupedmod", dm.getValue().get(0)))
.map(dm -> new EarlyLoadingException.ExceptionData("fml.modloading.dupedmod", dm.getValue().get(0), Objects.toString(dm.getValue().get(0))))
.collect(Collectors.toList());
throw new EarlyLoadingException("Duplicate mods found", null, duplicateModErrors);
}
@ -243,7 +244,7 @@ public class ModSorter
if (!missingVersions.isEmpty()) {
final List<EarlyLoadingException.ExceptionData> exceptionData = missingVersions
.stream()
.map(mv -> new EarlyLoadingException.ExceptionData("fml.modloading.missingdependency",
.map(mv -> new EarlyLoadingException.ExceptionData("fml.modloading.missingdependency", mv.getOwner(),
mv.getModId(), mv.getOwner().getModId(), mv.getVersionRange(),
modVersions.getOrDefault(mv.getModId(), new DefaultArtifactVersion("null"))))
.collect(Collectors.toList());

View file

@ -19,6 +19,7 @@
package net.minecraftforge.fml.loading.moddiscovery;
import com.google.common.base.Strings;
import net.minecraftforge.fml.loading.StringUtils;
import net.minecraftforge.forgespi.language.IConfigurable;
import net.minecraftforge.forgespi.language.IModFileInfo;
@ -65,7 +66,7 @@ public class ModFileInfo implements IModFileInfo, IConfigurable
.map(MavenVersionAdapter::createFromVersionSpec)
.orElseThrow(()->new InvalidModFileException("Missing ModLoader version in file", this));
this.license = config.<String>getConfigElement("license")
.orElseThrow(()->new InvalidModFileException("Missing License, please supply a license.", this));
.orElse("");
this.showAsResourcePack = config.<Boolean>getConfigElement("showAsResourcePack").orElse(false);
this.properties = config.<Map<String, Object>>getConfigElement("properties").orElse(Collections.emptyMap());
this.modFile.setFileProperties(this.properties);
@ -147,4 +148,9 @@ public class ModFileInfo implements IModFileInfo, IConfigurable
{
return issueURL;
}
public boolean missingLicense()
{
return Strings.isNullOrEmpty(license);
}
}

View file

@ -120,6 +120,11 @@ public class ModLoader
this.loadingWarnings = FMLLoader.getLoadingModList().
getBrokenFiles().stream().map(file -> new ModLoadingWarning(null, ModLoadingStage.VALIDATE,
InvalidModIdentifier.identifyJarProblem(file.getFilePath()).orElse("fml.modloading.brokenfile"), file.getFileName())).collect(Collectors.toList());
FMLLoader.getLoadingModList()
.getModFiles().stream().filter(ModFileInfo::missingLicense) //Search for files with missing licenses
.filter(modFileInfo -> modFileInfo.getMods().stream().noneMatch(thisModInfo -> this.loadingExceptions.stream().map(ModLoadingException::getModInfo).anyMatch(otherInfo -> otherInfo == thisModInfo))) //Ignore files where any other mod already encountered an error
.map(modFileInfo -> new ModLoadingException(null, ModLoadingStage.VALIDATE, "fml.modloading.missinglicense", null, modFileInfo.getFile()))
.forEach(this.loadingExceptions::add);
LOGGER.debug(CORE, "Loading Network data for FML net version: {}", FMLNetworkConstants.init());
CrashReportExtender.registerCrashCallable("ModLauncher", FMLLoader::getLauncherInfo);
CrashReportExtender.registerCrashCallable("ModLauncher launch target", FMLLoader::launcherHandlerName);

View file

@ -61,7 +61,7 @@ public class ModLoadingException extends RuntimeException
}
static Stream<ModLoadingException> fromEarlyException(final EarlyLoadingException e) {
return e.getAllData().stream().map(ed->new ModLoadingException(null, ModLoadingStage.VALIDATE, ed.getI18message(), e.getCause(), ed.getArgs()));
return e.getAllData().stream().map(ed->new ModLoadingException(ed.getModInfo(), ModLoadingStage.VALIDATE, ed.getI18message(), e.getCause(), ed.getArgs()));
}
public String getI18NMessage() {

View file

@ -58,6 +58,7 @@
"fml.modloading.brokenfile.optifine": "File {2} is an incompatible version of OptiFine",
"fml.modloading.brokenfile.invalidzip": "File {2} is not a jar file",
"fml.modloading.brokenresources": "File {2} failed to load a valid ResourcePackInfo",
"fml.modloading.missinglicense": "Missing License Information in file {3}",
"fml.resources.modresources": "Resources for {0} mod files",
"fml.messages.artifactversion.ornotinstalled":"{0,ornull,fml.messages.artifactversion.notinstalled}",