ServerPackHandler

class ServerPackHandler(apiProperties: ApiProperties, versionMeta: VersionMeta, utilities: Utilities, apiPlugins: ApiPlugins, modScanner: ModScanner)

Everything revolving around creating a server pack. The intended workflow is to create a PackConfig and run it through any of the available de.griefed.serverpackcreator.api.config.ConfigurationHandler.checkConfiguration-variants, and then call run with the previously checked configuration model. You may run with an unchecked configuration model, but no guarantees or promises, yes not even support, is given for running a model without checking it first.

This class also gives you access to the methods which are responsible for creating the server pack, in case you want to do things manually.

The methods in question are:

If you want to execute extensions, see

Author

Griefed

Parameters

apiProperties

Base settings of ServerPackCreator needed for server pack generation, such as access to the directories, script templates and so on.

versionMeta

Meta for modloader and version specific checks and information gathering, such as modloader installer downloads.

utilities

Common utilities used across ServerPackCreator.

apiPlugins

Any addons which a user may want to execute during the generation of a server pack.

modScanner

In case a user enabled automatic sideness detection, this will exclude clientside-only mods from a server pack.

Constructors

Link copied to clipboard
constructor(apiProperties: ApiProperties, versionMeta: VersionMeta, utilities: Utilities, apiPlugins: ApiPlugins, modScanner: ModScanner)

Properties

Link copied to clipboard
Link copied to clipboard
val log: KotlinLogger
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun addEventListener(genericEventListener: SPCGenericListener)
fun addEventListener(postGenListener: SPCPostGenListener)
fun addEventListener(preServerPackGenerationListener: SPCPreServerPackGenerationListener)
fun addEventListener(preServerPackZipListener: SPCPreServerPackZipListener)
Link copied to clipboard
fun cleanupEnvironment(deleteZip: Boolean, destination: String)

Deletes all files, directories and ZIP-archives of previously generated server packs to ensure newly generated server pack is as clean as possible. This will completely empty the server pack directory, so use with caution!

Link copied to clipboard
fun copyFiles(modpackDir: String, inclusions: ArrayList<InclusionSpecification>, clientMods: List<String>, whitelist: List<String>, minecraftVersion: String, destination: String, modloader: String, overwrite: Boolean): List<File>

Copies all specified directories and mods, excluding clientside-only mods, from the modpack directory into the server pack directory. If a source/file;destination/file -combination is provided, the specified source-file is copied to the specified destination-file. One of the reasons as to why it is recommended to run a given ConfigurationModel through the ConfigurationHandler first, is because the ConfigurationHandler will resolve links to their files first before then correcting the given ConfigurationModel.

Link copied to clipboard
fun copyIcon(destination: String, pathToServerIcon: String)

Copies the server-icon.png into server pack. The sever-icon is automatically scaled to a resolution of 64x64 pixels.

Link copied to clipboard
fun copyProperties(destination: String, pathToServerProperties: String)

Copies the server.properties into server pack.

Link copied to clipboard
fun createServerRunFiles(scriptSettings: HashMap<String, String>, destination: String, isLocal: Boolean)

Create start-scripts for the generated server pack using the templates the user has defined for their instance of ServerPackCreator.

Link copied to clipboard
fun exclude(userSpecifiedExclusion: String, userSpecifiedModsWhitelist: List<String>, modsInModpack: TreeSet<File>)

Go through the mods in the modpack and exclude any of the user-specified clientside-only mods according to the filter method set in the serverpackcreator.properties. For available filters, see ExclusionFilter.

Link copied to clipboard
fun excludeFileOrDirectory(modpackDir: String, fileToCheckFor: File, exclusions: List<Regex>): Boolean

Check whether the given file or directory should be excluded from the server pack.

Link copied to clipboard
fun excludeMods(autodiscoveredClientMods: List<File>, modsInModpack: TreeSet<File>)

Exclude every automatically discovered clientside-only mod from the list of mods in the modpack.

Link copied to clipboard
fun excludeUserSpecifiedMod(userSpecifiedExclusions: List<String>, userSpecifiedModsWhitelist: List<String>, modsInModpack: TreeSet<File>)

Exclude user-specified mods from the server pack.

Link copied to clipboard
fun getDirectoryFiles(source: String, destination: String): List<ServerPackFile>

Recursively acquire all files and directories inside the given directory as a list of ServerPackFile.

Link copied to clipboard
fun getExplicitFiles(source: String, destination: String, modpackDir: String, serverPackDestination: String): MutableList<ServerPackFile>

Gather a list of all files from an explicit source;destination-combination. If the source is a file, a singular ServerPackFile is returned. If the source is a directory, then all files in said directory are returned.

Link copied to clipboard
fun getImprovedFabricLauncher(minecraftVersion: String, fabricVersion: String, destination: String)

Download and provide the improved Fabric Server Launcher, if it is available for the given Minecraft and Fabric version.

Link copied to clipboard
fun getModsToInclude(modsDir: String, userSpecifiedClientMods: List<String>, userSpecifiedModsWhitelist: List<String>, minecraftVersion: String, modloader: String): List<File>

Generates a list of all mods to include in the server pack. If the user specified clientside-mods to exclude, and/or if the automatic exclusion of clientside-only mods is active, they will be excluded, too.

Link copied to clipboard
fun getSaveFiles(clientDir: String, directory: String, destination: String): List<ServerPackFile>

Recursively acquire all files and directories inside the given save-directory as a list of ServerPackFile.

Link copied to clipboard
fun getServerFiles(inclusion: InclusionSpecification, modpackDir: String, destination: String, exclusions: MutableList<Regex>, clientMods: List<String>, whitelist: List<String>, minecraftVersion: String, modloader: String): List<ServerPackFile>
Link copied to clipboard

Acquire the destination directory in which the server pack will be generated. The directory in which the server pack will be created has all its spaces replaces with underscores, so Survive Create Prosper 4 - 5.0.1 would become Survive_Create_Prosper_4_-_5.0.1 Even though it is the year 2022, spaces in paths can and do still cause trouble. Such as for Powershell scripts. Powershell throws a complete fit if the path contains spaces....so, we remove them. Better safe than sorry.

Link copied to clipboard
fun postInstallCleanup(destination: String)

Cleans up the server_pack directory by deleting left-over files from modloader installations and version checking.

Link copied to clipboard
fun preInstallationCleanup(destination: String)

Delete files and folders from previous installations to prevent errors during server installation due to already existing files.

Link copied to clipboard
fun regexWalk(source: File, destination: String, regex: Regex, serverPackFiles: MutableList<ServerPackFile>)

Walk through the specified directory and add a ServerPackFile for every file/folder which matches the given regex.

Link copied to clipboard
fun replacePlaceholders(isLocal: Boolean, content: String, scriptSettings: HashMap<String, String>): String

Replace placeholders for script settings in the given content with their respective values, both provided via the HashMap scriptSettings.

Link copied to clipboard

Create a server pack from a given instance of PackConfig.

Link copied to clipboard
fun serverDownloadable(mcVersion: String, modloader: String, modloaderVersion: String): Boolean

Check whether the installer for the given combination of Minecraft version, modloader and modloader version is available/reachable.

Link copied to clipboard
fun zipBuilder(minecraftVersion: String, destination: String, modloader: String, modloaderVersion: String): Optional<File>

Creates a ZIP-archive of specified directory. Depending on the property de.griefed.serverpackcreator.serverpack.zip.exclude.enabled, files will be excluded. To customize the files which will be excluded, the property de.griefed.serverpackcreator.serverpack.zip.exclude must be configured accordingly. The created ZIP-archive will be stored alongside the specified destination, with _server_pack.zip appended to its name.