User: rednesto Date: 15 Jul 24 12:28 Revision: 6bef7af0d4eacfaa8449cd100d9326acee7aa246 Summary: Remove unused McpVersion classes TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9455&personal=false Index: src/main/kotlin/platform/mcp/McpVersionPair.kt =================================================================== --- src/main/kotlin/platform/mcp/McpVersionPair.kt (revision d9c560c208ce4df12beb8fb62f25fa59127f8637) +++ src/main/kotlin/platform/mcp/McpVersionPair.kt (revision d9c560c208ce4df12beb8fb62f25fa59127f8637) @@ -1,44 +0,0 @@ -/* - * Minecraft Development for IntelliJ - * - * https://mcdev.io/ - * - * Copyright (C) 2024 minecraft-dev - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, version 3.0 only. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.demonwav.mcdev.platform.mcp - -import com.demonwav.mcdev.util.SemanticVersion - -data class McpVersionPair(val mcpVersion: String, val mcVersion: SemanticVersion) : Comparable { - - override fun compareTo(other: McpVersionPair): Int { - val mcRes = mcVersion.compareTo(other.mcVersion) - if (mcRes != 0) { - return mcRes - } - val thisStable = mcpVersion.startsWith("stable") - val thatStable = other.mcpVersion.startsWith("stable") - return if (thisStable && !thatStable) { - -1 - } else if (!thisStable && thatStable) { - 1 - } else { - val thisNum = mcpVersion.substringAfter('_') - val thatNum = other.mcpVersion.substringAfter('_') - thisNum.toInt().compareTo(thatNum.toInt()) - } - } -} Index: src/main/kotlin/platform/mcp/version/McpVersion.kt =================================================================== --- src/main/kotlin/platform/mcp/version/McpVersion.kt (revision d9c560c208ce4df12beb8fb62f25fa59127f8637) +++ src/main/kotlin/platform/mcp/version/McpVersion.kt (revision d9c560c208ce4df12beb8fb62f25fa59127f8637) @@ -1,131 +0,0 @@ -/* - * Minecraft Development for IntelliJ - * - * https://mcdev.io/ - * - * Copyright (C) 2024 minecraft-dev - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, version 3.0 only. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.demonwav.mcdev.platform.mcp.version - -import com.demonwav.mcdev.platform.mcp.McpVersionPair -import com.demonwav.mcdev.util.SemanticVersion -import com.demonwav.mcdev.util.fromJson -import com.demonwav.mcdev.util.sortVersions -import com.google.gson.Gson -import java.io.IOException -import java.net.URL -import kotlin.math.min - -class McpVersion private constructor(private val map: Map>>) { - - val versions: List by lazy { - sortVersions(map.keys) - } - - data class McpVersionSet(val goodVersions: List, val badVersions: List) - - private fun getSnapshot(version: SemanticVersion): McpVersionSet { - return get(version, "snapshot") - } - - private fun getStable(version: SemanticVersion): McpVersionSet { - return get(version, "stable") - } - - private operator fun get(version: SemanticVersion, type: String): McpVersionSet { - val good = ArrayList() - val bad = ArrayList() - - val keySet = map.keys - for (mcVersion in keySet) { - val versions = map[mcVersion] - if (versions != null) { - versions[type]?.let { vers -> - val mcVersionParsed = SemanticVersion.parse(mcVersion) - val pairs = vers.map { McpVersionPair("${type}_$it", mcVersionParsed) } - if (mcVersionParsed.startsWith(version)) { - good.addAll(pairs) - } else { - bad.addAll(pairs) - } - } - } - } - - return McpVersionSet(good, bad) - } - - fun getMcpVersionList(version: SemanticVersion): List { - val limit = 50 - - val result = ArrayList(limit * 4) - - val majorVersion = version.take(2) - val stable = getStable(majorVersion) - val snapshot = getSnapshot(majorVersion) - - fun mapTopTo(source: List, dest: MutableList, limit: Int, isRed: Boolean) { - val tempList = ArrayList(source).apply { sortDescending() } - for (i in 0 until min(limit, tempList.size)) { - dest += McpVersionEntry(tempList[i], isRed) - } - } - - mapTopTo(stable.goodVersions, result, limit, false) - mapTopTo(snapshot.goodVersions, result, limit, false) - - // If we're already at the limit we don't need to go through the bad list - if (result.size >= limit) { - return result.subList(0, min(limit, result.size)) - } - - // The bad pairs don't match the current MC version, but are still available to the user - // We will color them red - mapTopTo(stable.badVersions, result, limit, true) - mapTopTo(snapshot.badVersions, result, limit, true) - - return result.subList(0, min(limit, result.size)) - } - - companion object { - fun downloadData(): McpVersion? { - val bspkrsMappings = try { - val bspkrsText = URL("https://maven.minecraftforge.net/de/oceanlabs/mcp/versions.json").readText() - Gson().fromJson>>>(bspkrsText) - } catch (ignored: IOException) { - mutableMapOf() - } - - val tterragMappings = try { - val tterragText = URL("https://assets.tterrag.com/temp_mappings.json").readText() - Gson().fromJson>>>(tterragText) - } catch (ignored: IOException) { - emptyMap() - } - - // Merge the temporary mappings list into the main one, temporary solution for 1.16 - tterragMappings.forEach { (mcVersion, channels) -> - val existingChannels = bspkrsMappings.getOrPut(mcVersion, ::mutableMapOf) - channels.forEach { (channelName, newVersions) -> - val existingVersions = existingChannels.getOrPut(channelName, ::mutableListOf) - existingVersions.addAll(newVersions) - } - } - - return if (bspkrsMappings.isEmpty()) null else McpVersion(bspkrsMappings) - } - } -} Index: src/main/kotlin/platform/mcp/version/McpVersionEntry.kt =================================================================== --- src/main/kotlin/platform/mcp/version/McpVersionEntry.kt (revision d9c560c208ce4df12beb8fb62f25fa59127f8637) +++ src/main/kotlin/platform/mcp/version/McpVersionEntry.kt (revision d9c560c208ce4df12beb8fb62f25fa59127f8637) @@ -1,39 +0,0 @@ -/* - * Minecraft Development for IntelliJ - * - * https://mcdev.io/ - * - * Copyright (C) 2024 minecraft-dev - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, version 3.0 only. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.demonwav.mcdev.platform.mcp.version - -import com.demonwav.mcdev.platform.mcp.McpVersionPair - -class McpVersionEntry(val versionPair: McpVersionPair, val isRed: Boolean = false) { - - override fun toString(): String { - return if (isRed) { - RED_START + versionPair.mcpVersion + RED_END - } else { - versionPair.mcpVersion - } - } - - companion object { - private const val RED_START = "" - private const val RED_END = "" - } -}