From f7b700bcf5a49ac4573962de4a24245b0c919d43 Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 2 Aug 2024 00:16:28 +0200 Subject: [PATCH] chore: use lenient reader --- src/main/kotlin/com/mineinabyss/packy/PackyGenerator.kt | 3 +-- src/main/kotlin/com/mineinabyss/packy/PackyPlugin.kt | 6 +++++- src/main/kotlin/com/mineinabyss/packy/PackyServer.kt | 5 +---- src/main/kotlin/com/mineinabyss/packy/PackySquash.kt | 2 +- .../kotlin/com/mineinabyss/packy/config/PackyContext.kt | 4 ++++ .../kotlin/com/mineinabyss/packy/helpers/PackyHelpers.kt | 7 +++---- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/mineinabyss/packy/PackyGenerator.kt b/src/main/kotlin/com/mineinabyss/packy/PackyGenerator.kt index 58329f0..1c12436 100644 --- a/src/main/kotlin/com/mineinabyss/packy/PackyGenerator.kt +++ b/src/main/kotlin/com/mineinabyss/packy/PackyGenerator.kt @@ -12,7 +12,6 @@ import com.mineinabyss.packy.helpers.readPack import kotlinx.coroutines.* import team.unnamed.creative.ResourcePack import team.unnamed.creative.base.Writable -import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter import team.unnamed.creative.sound.SoundRegistry import kotlin.io.path.div import kotlin.io.path.exists @@ -63,7 +62,7 @@ object PackyGenerator { cachedPack.sortItemOverrides() PackObfuscator(cachedPack).obfuscatePack() - val builtPack = MinecraftResourcePackWriter.minecraft().build(cachedPack) + val builtPack = packy.writer.build(cachedPack) PackyPack(builtPack, templateIds).apply { cachedPacks[templateIds] = this cachedPacksByteArray[templateIds] = builtPack.data().toByteArray() diff --git a/src/main/kotlin/com/mineinabyss/packy/PackyPlugin.kt b/src/main/kotlin/com/mineinabyss/packy/PackyPlugin.kt index 6209771..0d2611f 100644 --- a/src/main/kotlin/com/mineinabyss/packy/PackyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/packy/PackyPlugin.kt @@ -20,6 +20,8 @@ import kotlinx.coroutines.Job import kotlinx.serialization.modules.EmptySerializersModule import org.bukkit.plugin.java.JavaPlugin import team.unnamed.creative.ResourcePack +import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackReader +import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter class PackyPlugin : JavaPlugin() { @@ -57,13 +59,15 @@ class PackyPlugin : JavaPlugin() { override val accessToken: PackyAccessToken by config("accessToken", dataFolder.toPath(), PackyAccessToken()) override val defaultPack: ResourcePack = ResourcePack.resourcePack() override val logger by plugin.observeLogger() + override val reader = MinecraftResourcePackReader.builder().lenient(true).build() + override val writer = MinecraftResourcePackWriter.builder().prettyPrinting(false).build() }) PackyGenerator.activeGeneratorJob.apply { values.forEach(Job::cancel) }.clear() PackyGenerator.cachedPacks.clear() PackyGenerator.cachedPacksByteArray.clear() PackyDownloader.downloadTemplates() - TemplateLoadTriggers.registerTemplateHandlers() + //TemplateLoadTriggers.registerTemplateHandlers() PackyGenerator.setupRequiredPackTemplates() PackyServer.registerConfigPacketHandler() } diff --git a/src/main/kotlin/com/mineinabyss/packy/PackyServer.kt b/src/main/kotlin/com/mineinabyss/packy/PackyServer.kt index 8a79b94..eb35f3a 100644 --- a/src/main/kotlin/com/mineinabyss/packy/PackyServer.kt +++ b/src/main/kotlin/com/mineinabyss/packy/PackyServer.kt @@ -30,10 +30,7 @@ import net.minecraft.server.MinecraftServer import net.minecraft.server.network.ConfigurationTask import net.minecraft.server.network.ServerConfigurationPacketListenerImpl import net.minecraft.server.network.config.ServerResourcePackConfigurationTask -import org.bukkit.craftbukkit.CraftServer import org.bukkit.entity.Player -import org.bukkit.event.player.PlayerResourcePackStatusEvent -import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter import team.unnamed.creative.server.ResourcePackServer import team.unnamed.creative.server.handler.ResourcePackRequestHandler import java.net.URI @@ -124,7 +121,7 @@ object PackyServer { private val handler = ResourcePackRequestHandler { _, exchange -> val data = exchange.requestURI.parseTemplateIds() ?.let { templateIds -> PackyGenerator.cachedPacksByteArray[templateIds] } - ?: MinecraftResourcePackWriter.minecraft().build(packy.defaultPack).data().toByteArray() + ?: packy.writer.build(packy.defaultPack).data().toByteArray() exchange.responseHeaders["Content-Type"] = "application/zip" exchange.sendResponseHeaders(200, data.size.toLong()) exchange.responseBody.use { responseStream -> responseStream.write(data) } diff --git a/src/main/kotlin/com/mineinabyss/packy/PackySquash.kt b/src/main/kotlin/com/mineinabyss/packy/PackySquash.kt index b28adf9..3f9d4c2 100644 --- a/src/main/kotlin/com/mineinabyss/packy/PackySquash.kt +++ b/src/main/kotlin/com/mineinabyss/packy/PackySquash.kt @@ -26,7 +26,7 @@ object PackySquash { val packName = UUID.randomUUID().toString() val packDir = packy.plugin.dataFolder.resolve("packsquash").resolve(packName) - MinecraftResourcePackWriter.minecraft().writeToDirectory(packDir, resourcePack) + packy.writer.writeToDirectory(packDir, resourcePack) val toml = packDir.parentFile.resolve("$packName.toml") val tomlContent = baseToml.readText() diff --git a/src/main/kotlin/com/mineinabyss/packy/config/PackyContext.kt b/src/main/kotlin/com/mineinabyss/packy/config/PackyContext.kt index ebb47ef..13f2671 100644 --- a/src/main/kotlin/com/mineinabyss/packy/config/PackyContext.kt +++ b/src/main/kotlin/com/mineinabyss/packy/config/PackyContext.kt @@ -4,6 +4,8 @@ import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.messaging.ComponentLogger import com.mineinabyss.packy.PackyPlugin import team.unnamed.creative.ResourcePack +import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackReader +import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter val packy by DI.observe() interface PackyContext { @@ -13,4 +15,6 @@ interface PackyContext { val templates: Map val accessToken: PackyAccessToken val logger: ComponentLogger + val reader: MinecraftResourcePackReader + val writer: MinecraftResourcePackWriter } diff --git a/src/main/kotlin/com/mineinabyss/packy/helpers/PackyHelpers.kt b/src/main/kotlin/com/mineinabyss/packy/helpers/PackyHelpers.kt index 3e27022..837d2e3 100644 --- a/src/main/kotlin/com/mineinabyss/packy/helpers/PackyHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/packy/helpers/PackyHelpers.kt @@ -16,15 +16,14 @@ import kotlin.io.path.deleteIfExists import kotlin.io.path.deleteRecursively fun File.readPack(): ResourcePack? { - val reader = MinecraftResourcePackReader.minecraft() return runCatching { when { !exists() -> null - isDirectory && !listFiles().isNullOrEmpty() -> reader.readFromDirectory(this) - extension == "zip" -> reader.readFromZipFile(this) + isDirectory && !listFiles().isNullOrEmpty() -> packy.reader.readFromDirectory(this) + extension == "zip" -> packy.reader.readFromZipFile(this) else -> null } - }.getOrNull() + }.onFailure { packy.logger.w(this.name + ": " + it.message) }.getOrNull() } @OptIn(ExperimentalPathApi::class)