All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.de.griefed.serverpackcreator.api.Pack.kt Maven / Gradle / Ivy

Go to download

ServerPackCreators API, to create server packs from Forge, Fabric, Quilt, LegacyFabric and NeoForge modpacks.

The newest version!
/* Copyright (C) 2024  Griefed
 *
 * This library 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; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 *
 * The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
 */
package de.griefed.serverpackcreator.api

import de.griefed.serverpackcreator.api.utilities.CommentedConfig

/**
 * A server pack configuration from which to generate a server pack.
 *
 * @author Griefed
 */
@Suppress("MemberVisibilityCanBePrivate")
abstract class Pack {
    protected val forge = "^forge$".toRegex()
    protected val neoForge = "^neoforge$".toRegex()
    protected val fabric = "^fabric$".toRegex()
    protected val quilt = "^quilt$".toRegex()
    protected val legacyFabric = "^legacyfabric$".toRegex()
    protected val whitespace = "^\\s+$".toRegex()

    val clientMods: ArrayList = ArrayList(1000)
    val modsWhitelist: ArrayList = ArrayList(1000)
    val inclusions: ArrayList = ArrayList(100)
    val scriptSettings = HashMap(100)
    val pluginsConfigs = HashMap>(20)
    var modpackDir = ""
    var minecraftVersion = ""
    var modloaderVersion = ""
    var javaArgs = ""
    var serverPackSuffix = ""
    var serverIconPath = ""
    var serverPropertiesPath = ""
    var modloader = ""
        set(newModLoader) {
            if (newModLoader.lowercase().matches(forge)) {
                field = "Forge"
            } else if (newModLoader.lowercase().matches(neoForge)) {
                field = "NeoForge"
            } else if (newModLoader.lowercase().matches(fabric)) {
                field = "Fabric"
            } else if (newModLoader.lowercase().matches(quilt)) {
                field = "Quilt"
            } else if (newModLoader.lowercase().matches(legacyFabric)) {
                field = "LegacyFabric"
            }
        }
    var isServerIconInclusionDesired = true
    var isServerPropertiesInclusionDesired = true
    var isZipCreationDesired = true
    var modpackJson: J? = null
    var configVersion: String? = null

    open var projectName: String? = null
    open var fileName: String? = null
    open var fileDiskName: String? = null

    /**
     * Save this configuration.
     *
     * @param destination The file to store the configuration in.
     * @return The configuration for further operations.
     * @author Griefed
     */
    abstract fun save(destination: F, apiProperties: ApiProperties): P

    fun setPluginsConfigs(pluginConfigs: HashMap>) {
        this.pluginsConfigs.clear()
        this.pluginsConfigs.putAll(pluginConfigs)
    }

    fun getPluginConfigs(pluginId: String): ArrayList {
        if (!pluginsConfigs.containsKey(pluginId)) {
            pluginsConfigs[pluginId] = java.util.ArrayList(100)
        }
        return pluginsConfigs[pluginId]!!
    }

    fun setClientMods(newClientMods: MutableList) {
        clientMods.clear()
        newClientMods.removeIf { entry: String -> entry.isBlank() || entry.matches(whitespace) }
        clientMods.addAll(newClientMods)
    }

    fun setModsWhitelist(newModsWhitelist: MutableList) {
        modsWhitelist.clear()
        newModsWhitelist.removeIf { entry: String -> entry.isBlank() || entry.matches(whitespace) }
        modsWhitelist.addAll(newModsWhitelist)
    }

    fun setInclusions(newCopyDirs: ArrayList) {
        inclusions.clear()
        inclusions.addAll(newCopyDirs)
    }

    fun setScriptSettings(settings: HashMap) {
        scriptSettings.clear()
        scriptSettings.putAll(settings)
    }

    override fun toString(): String {
        return "Pack(" +
                " clientMods=$clientMods," +
                " whiteList=$modsWhitelist," +
                " copyDirs=$inclusions," +
                " scriptSettings=$scriptSettings," +
                " pluginsConfigs=$pluginsConfigs," +
                " modpackDir='$modpackDir'," +
                " minecraftVersion='$minecraftVersion'," +
                " modloaderVersion='$modloaderVersion'," +
                " javaArgs='$javaArgs'," +
                " serverPackSuffix='$serverPackSuffix'," +
                " serverIconPath='$serverIconPath'," +
                " serverPropertiesPath='$serverPropertiesPath'," +
                " modloader='$modloader'," +
                " isServerIconInclusionDesired=$isServerIconInclusionDesired," +
                " isServerPropertiesInclusionDesired=$isServerPropertiesInclusionDesired," +
                " isZipCreationDesired=$isZipCreationDesired)"
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy