User: rednesto Date: 28 Nov 24 14:31 Revision: 692c5a91dcd1cf00ea5f8333b1f08e9f816a9c42 Summary: Fix #2382 Use latest parchment version available if none matches normally Parchment is not always up-to-date and thus might not be available for the latest MC versions, but will still work fine. This commit makes the parchment properties show all known versions automatically if the selected MC version is not directly supported TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9787&personal=false Index: src/main/kotlin/creator/custom/types/ParchmentCreatorProperty.kt =================================================================== --- src/main/kotlin/creator/custom/types/ParchmentCreatorProperty.kt (revision fed7233c1b511c4f116dd2d8cb31502354a67ee3) +++ src/main/kotlin/creator/custom/types/ParchmentCreatorProperty.kt (revision 692c5a91dcd1cf00ea5f8333b1f08e9f816a9c42) @@ -125,12 +125,12 @@ val platformMcVersionPropertyName = descriptor.parameters?.get("minecraftVersionProperty") as? String val platformMcVersionProperty = properties[platformMcVersionPropertyName] if (platformMcVersionProperty != null) { - graphProperty.dependsOn(platformMcVersionProperty.graphProperty, true) { + platformMcVersionProperty.graphProperty.afterChange { val minecraftVersion = getPlatformMinecraftVersion() - if (minecraftVersion != null) { - graphProperty.get().copy(minecraftVersion = minecraftVersion) - } else { - graphProperty.get() + if (mcVersionsModel.getIndexOf(minecraftVersion) == -1) { + refreshVersionsLists(forceLatestVersions = true) + } else if (minecraftVersion != null) { + graphProperty.set(graphProperty.get().copy(minecraftVersion = minecraftVersion)) } } } @@ -167,17 +167,12 @@ downloadVersions(context) { refreshVersionsLists() - - val minecraftVersion = getPlatformMinecraftVersion() - if (minecraftVersion != null) { - mcVersionProperty.set(minecraftVersion) - } - } + } + } - } - private fun refreshVersionsLists(updateMcVersions: Boolean = true) { - val includeOlderMcVersions = includeOlderMcVersionsProperty.get() - val includeSnapshots = includeSnapshotsProperty.get() + private fun refreshVersionsLists(updateMcVersions: Boolean = true, forceLatestVersions: Boolean = false) { + val includeOlderMcVersions = includeOlderMcVersionsProperty.get() || forceLatestVersions + val includeSnapshots = includeSnapshotsProperty.get() || forceLatestVersions if (updateMcVersions) { val platformMcVersion = getPlatformMinecraftVersion() @@ -199,16 +194,24 @@ mcVersionsModel.removeAllElements() mcVersionsModel.addAll(mcVersions) + if (forceLatestVersions) { + mcVersionProperty.set(mcVersions.maxOrNull() ?: emptyVersion) + } else { - val selectedMcVersion = when { - mcVersionProperty.get() in mcVersions -> mcVersionProperty.get() - defaultValue.minecraftVersion in mcVersions -> defaultValue.minecraftVersion + val selectedMcVersion = when { + mcVersionProperty.get() in mcVersions -> mcVersionProperty.get() + defaultValue.minecraftVersion in mcVersions -> defaultValue.minecraftVersion - else -> getPlatformMinecraftVersion() ?: mcVersions.first() + else -> { + refreshVersionsLists(forceLatestVersions = true) + return + // getPlatformMinecraftVersion() ?: mcVersions.first() - } + } + } - if (mcVersionProperty.get() != selectedMcVersion) { - mcVersionProperty.set(selectedMcVersion) - } - } + if (mcVersionProperty.get() != selectedMcVersion) { + mcVersionProperty.set(selectedMcVersion) + } + } + } val selectedMcVersion = mcVersionProperty.get() val parchmentVersions = availableParchmentVersions.asSequence() @@ -218,8 +221,12 @@ .toList() versionsModel.removeAllElements() versionsModel.addAll(parchmentVersions) + if (forceLatestVersions) { + versionProperty.set(parchmentVersions.maxOrNull() ?: emptyVersion) + } else { - versionProperty.set(parchmentVersions.firstOrNull() ?: emptyVersion) - } + versionProperty.set(parchmentVersions.firstOrNull() ?: emptyVersion) + } + } private fun getPlatformMinecraftVersion(): SemanticVersion? { val platformMcVersionPropertyName = descriptor.parameters?.get("minecraftVersionProperty") as? String