diff --git a/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.kt b/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.kt index 351da3f..770c9cd 100644 --- a/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.kt +++ b/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.kt @@ -6,9 +6,4 @@ import org.bukkit.plugin.java.JavaPlugin class IdofrontPlugin : JavaPlugin() { - override fun onEnable() { - Bukkit.getAsyncScheduler().runNow(this) { - MinecraftAssetExtractor.extractLatest() - } - } } diff --git a/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/MinecraftAssetExtractor.kt b/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/MinecraftAssetExtractor.kt index 728847d..d6ae120 100644 --- a/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/MinecraftAssetExtractor.kt +++ b/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/MinecraftAssetExtractor.kt @@ -15,7 +15,7 @@ import java.util.zip.ZipInputStream object MinecraftAssetExtractor { private const val VERSION_MANIFEST_URL = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" - lateinit var assetPath: File + val assetPath = Bukkit.getPluginsFolder().resolve("Idofront/assetCache/${Bukkit.getMinecraftVersion()}") fun extractLatest() { idofrontLogger.i("Extracting latest vanilla-assets...") @@ -74,21 +74,19 @@ object MinecraftAssetExtractor { }.onFailure { it.printStackTrace() }.getOrNull() ?: error("Failed to download client JAR") private fun findVersionInfoUrl(): String? { - val manifest = runCatching { - downloadJson(VERSION_MANIFEST_URL) - }.getOrNull() ?: error("Failed to download version manifest") - - val latest = manifest.getAsJsonObject("latest").get("release").asString - assetPath = Bukkit.getPluginsFolder().resolve("Idofront/assetCache/$latest") - + val version = Bukkit.getMinecraftVersion() if (!assetPath.mkdirs()) { - idofrontLogger.i("Latest has already been extracted for $latest, skipping...") + idofrontLogger.i("Latest has already been extracted for $version, skipping...") return null } + val manifest = runCatching { + downloadJson(VERSION_MANIFEST_URL) + }.getOrNull() ?: error("Failed to download version manifest") + return manifest.getAsJsonArray("versions").firstOrNull { - (it as? JsonObject)?.get("id")?.asString?.equals(latest) ?: false - }?.asJsonObject?.get("url")?.asString ?: error("Failed to find version inof url for version $latest") + (it as? JsonObject)?.get("id")?.asString?.equals(version) ?: false + }?.asJsonObject?.get("url")?.asString ?: error("Failed to find version inof url for version $version") } private fun downloadJson(url: String) = runCatching { JsonParser.parseString(URI.create(url).toURL().readText()) } diff --git a/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/ResourcePacks.kt b/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/ResourcePacks.kt index 8910bff..5437381 100644 --- a/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/ResourcePacks.kt +++ b/idofront-util/src/main/kotlin/com/mineinabyss/idofront/resourcepacks/ResourcePacks.kt @@ -11,7 +11,14 @@ object ResourcePacks { val resourcePackWriter = MinecraftResourcePackWriter.builder().prettyPrinting(true).build() val resourcePackReader = MinecraftResourcePackReader.builder().lenient(true).build() - val vanillaDefaultResourcePack by lazy { readToResourcePack(MinecraftAssetExtractor.assetPath) } + /** + * Loads a copy of the vanilla resourcepack for the current version + * If it has not been yet, it will first be extracted locally + * The ResourcePack instance does not contain any of the vanilla OGG files due to filesize optimizations + */ + val defaultVanillaResourcePack by lazy { + MinecraftAssetExtractor.assetPath.apply { if (!exists()) MinecraftAssetExtractor.extractLatest() }.let(::readToResourcePack) + } fun readToResourcePack(file: File): ResourcePack? { return runCatching {