Skip to content

Commit 520437d

Browse files
authored
Merge pull request #10 from ReviversMC/next/4.1.4
4.1.4
2 parents b5873b0 + 8d191e6 commit 520437d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.github.reviversmc.themodindex.validation"
7-
version = "4.1.3"
7+
version = "4.1.4"
88

99
repositories {
1010
mavenCentral()

src/main/kotlin/com/github/reviversmc/themodindex/validation/Validation.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,27 @@ fun main(args: Array<String>) {
3333
val availableManifests = indexJson.identifiers.map {
3434
if (it.lowercase() != it) throw IllegalStateException("Identifier \"$it\" is not lowercase.")
3535
if (it.split(":").size != 3) throw IllegalStateException("Identifier \"$it\" is not in the format \"modloader:modname:hash\".")
36-
it.substring(0, it.lastIndexOf(":"))
36+
it.substringBeforeLast(":")
3737
}.distinct()
3838

3939
val versionHashes = indexJson.identifiers.map { it.split(":")[2] }
4040

4141
//Protect against the rare chance where we have a hash collision
42-
if (versionHashes != versionHashes.distinct()) throw IllegalStateException("Duplicate version hashes found.")
42+
if (versionHashes != versionHashes.distinct()) {
43+
val distinctHashes = versionHashes.distinct()
44+
for (i in distinctHashes.indices) {
45+
if (versionHashes[i] != distinctHashes[i]) { //Duplicate found. The duplicate is versionHashes[i]
46+
val collidedIdentifiers =
47+
indexJson.identifiers.filter { it.substringAfterLast(":") == versionHashes[i] }
48+
val name = collidedIdentifiers.first().split(":")[1]
49+
if (collidedIdentifiers != collidedIdentifiers.filter { it.split(":")[1] == name }) {
50+
throw IllegalStateException("Hash collision found for the follow projects. A hash collision occurs when two or more different projects (the same project for a different mod loader does not count as separate projects) have the same hash for a file.\n" +
51+
"Projects: ${collidedIdentifiers.joinToString(", ")}\n" +
52+
"Hash: $versionHashes[$i]")
53+
}
54+
}
55+
}
56+
}
4357

4458
println("Index file validated successfully.")
4559

0 commit comments

Comments
 (0)