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.
This commit is contained in:
TDSTOS
2026-04-12 12:26:53 +02:00
parent 7005546e21
commit 26a29e8ba9
4 changed files with 38 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)

View File

@@ -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
}
}
}
}