Skip to content

Commit

Permalink
Ignore invalid mod versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Aug 21, 2023
1 parent 0fe1fb5 commit 686077d
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.su5ed.sinytra.connector.locator;

import com.electronwill.nightconfig.core.Config;
import com.mojang.logging.LogUtils;
import dev.su5ed.sinytra.connector.ConnectorUtil;
import dev.su5ed.sinytra.connector.loader.ConnectorLoaderModMetadata;
import net.fabricmc.loader.api.metadata.ContactInformation;
Expand All @@ -11,17 +12,22 @@
import net.minecraftforge.forgespi.language.IConfigurable;
import net.minecraftforge.forgespi.language.IModFileInfo;
import net.minecraftforge.forgespi.locating.IModFile;
import org.slf4j.Logger;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public final class ConnectorModMetadataParser {
private static final String DEFAULT_LICENSE = "All Rights Reserved";
// From ModInfo
private static final Pattern VALID_VERSION = Pattern.compile("^\\d+.*");
private static final Logger LOGGER = LogUtils.getLogger();

public static IModFileInfo createForgeMetadata(IModFile modFile, ConnectorLoaderModMetadata metadata) {
String modid = metadata.getId();
Expand All @@ -40,7 +46,13 @@ public static IModFileInfo createForgeMetadata(IModFile modFile, ConnectorLoader

Config modListConfig = config.createSubConfig();
modListConfig.add("modId", modid);
modListConfig.add("version", metadata.getNormalizedVersion());
String version = metadata.getNormalizedVersion();
// Validate version string. If it's invalid, we'll let FML assign a default version instead
if (VALID_VERSION.matcher(version).matches()) {
modListConfig.add("version", version);
} else {
LOGGER.warn("Ignoring invalid version for mod {} in file {}", modid, modFile.getFilePath());
}
modListConfig.add("displayName", metadata.getName());
modListConfig.add("description", metadata.getDescription());
metadata.getIconPath(-1).ifPresent(icon -> modListConfig.add("logoFile", icon));
Expand Down

0 comments on commit 686077d

Please sign in to comment.