From 26a29e8ba99b789a674c25d6e5cfe2a34f786e49 Mon Sep 17 00:00:00 2001 From: TDSTOS Date: Sun, 12 Apr 2026 12:26:53 +0200 Subject: [PATCH] Support .tar.gz maps and map-system toggle Add Apache Commons Compress dependency and relocate its packages for shading. Introduce a config guard (map-system.enabled) in SpeedHG.onWorldInit and DataPackManager.install to skip internal map handling when an external map system is enabled. Add untar() to WorldManager using TarArchiveInputStream + GzipCompressorInputStream and update extraction logic to handle .zip and .gz (.tar.gz) archives, extracting to the world parent folder as needed. --- build.gradle.kts | 3 ++ .../kotlin/club/mcscrims/speedhg/SpeedHG.kt | 3 ++ .../mcscrims/speedhg/world/DataPackManager.kt | 3 ++ .../mcscrims/speedhg/world/WorldManager.kt | 30 ++++++++++++++++++- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 27c2e6f..a07f934 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,6 +30,8 @@ dependencies { implementation(libs.kotlinxCoroutines) implementation(libs.kotlinxSerialization) + implementation("org.apache.commons:commons-compress:1.26.1") + compileOnly("com.lunarclient:apollo-api:1.2.4") compileOnly("com.lunarclient:apollo-extra-adventure4:1.2.4") @@ -56,6 +58,7 @@ tasks { relocate("fr.mrmicky.fastboard", "club.mcscrims.speedhg.libs.fastboard") relocate("com.zaxxer.hikari", "club.mcscrims.speedhg.libs.hikari") + relocate("org.apache.commons.compress", "club.mcscrims.speedhg.libs.compress") } build { diff --git a/src/main/kotlin/club/mcscrims/speedhg/SpeedHG.kt b/src/main/kotlin/club/mcscrims/speedhg/SpeedHG.kt index bc1842d..65c6e4e 100644 --- a/src/main/kotlin/club/mcscrims/speedhg/SpeedHG.kt +++ b/src/main/kotlin/club/mcscrims/speedhg/SpeedHG.kt @@ -148,6 +148,9 @@ class SpeedHG : JavaPlugin() { fun onWorldInit( event: WorldInitEvent ) { + if (config.getBoolean( "map-system.enabled" )) + return + val targetWorldName = config.getString( "map-system.target-world-name", "world" ) if ( event.world.name != targetWorldName ) return diff --git a/src/main/kotlin/club/mcscrims/speedhg/world/DataPackManager.kt b/src/main/kotlin/club/mcscrims/speedhg/world/DataPackManager.kt index acadfdb..f10b75b 100644 --- a/src/main/kotlin/club/mcscrims/speedhg/world/DataPackManager.kt +++ b/src/main/kotlin/club/mcscrims/speedhg/world/DataPackManager.kt @@ -54,6 +54,9 @@ class DataPackManager(private val plugin: SpeedHG) { * installiert den DataPack dort. Für den Normalfall gedacht. */ fun install() { + if (plugin.config.getBoolean( "map-system.enabled" )) + return + val worldName = plugin.config.getString("map-system.target-world-name", "world")!! val serverRoot = plugin.dataFolder.parentFile.parentFile val worldFolder = File(serverRoot, worldName) diff --git a/src/main/kotlin/club/mcscrims/speedhg/world/WorldManager.kt b/src/main/kotlin/club/mcscrims/speedhg/world/WorldManager.kt index 89bf98b..76ad006 100644 --- a/src/main/kotlin/club/mcscrims/speedhg/world/WorldManager.kt +++ b/src/main/kotlin/club/mcscrims/speedhg/world/WorldManager.kt @@ -1,6 +1,8 @@ package club.mcscrims.speedhg.world import club.mcscrims.speedhg.SpeedHG +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream import java.io.File import java.io.FileInputStream import java.io.FileOutputStream @@ -58,7 +60,11 @@ class WorldManager( plugin.logger.info( "[WorldManager] Ausgewählte Map: $randomMapName. Entpacke..." ) targetWorldFolder.mkdirs() - unzip( zipFile, targetWorldFolder ) + + if (zipFile.endsWith( ".zip" )) + unzip( zipFile, targetWorldFolder.parentFile ) + else if (zipFile.endsWith( ".gz" )) + untar( zipFile, targetWorldFolder.parentFile ) plugin.logger.info( "[WorldManager] Map erfolgreich entpackt!" ) } @@ -93,4 +99,26 @@ class WorldManager( } } + private fun untar( + tarGzFile: File, + targetDir: File + ) { + TarArchiveInputStream(GzipCompressorInputStream(FileInputStream( tarGzFile ))).use { tais -> + var entry = tais.nextEntry + + while( entry != null ) + { + val newFile = File( targetDir, entry.name ) + if ( entry.isDirectory ) + newFile.mkdirs() + else + { + newFile.parentFile.mkdirs() + FileOutputStream( newFile ).use { fos -> tais.copyTo( fos ) } + } + entry = tais.nextEntry + } + } + } + } \ No newline at end of file