Class ServerPackHandler

    • Constructor Detail

      • ServerPackHandler

        ServerPackHandler(ApiProperties apiProperties, VersionMeta versionMeta, Utilities utilities, ApiPlugins apiPlugins, ModScanner modScanner)
        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.
    • Method Detail

      • getLog

         final KotlinLogger getLog()
      • getServerPackDestination

         final String getServerPackDestination(PackConfig packConfig)

        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.

        Parameters:
        packConfig - Model containing the modpack directory of the modpack from which the server pack will be generated.
        Returns:

        The complete path to the directory in which the server pack will be generated.

      • run

         final ServerPackGeneration run(PackConfig packConfig)

        Create a server pack from a given instance of PackConfig.

        Parameters:
        packConfig - An instance of PackConfig which contains the configuration of the modpack from which the server pack is to be created.
        Returns:

        true if the server pack was successfully generated.

      • cleanupEnvironment

         final Unit cleanupEnvironment(Boolean deleteZip, String destination)

        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!

        Parameters:
        deleteZip - Whether to delete the server pack ZIP-archive.
        destination - The destination at which to clean up in.
      • copyFiles

         final List<File> copyFiles(String modpackDir, ArrayList<InclusionSpecification> inclusions, List<String> clientMods, List<String> whitelist, String minecraftVersion, String destination, String modloader, Boolean overwrite)

        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.

        Parameters:
        modpackDir - Files and directories are copied into the server_pack directory inside the modpack directory.
        inclusions - All directories and files therein to copy to the server pack.
        clientMods - List of clientside-only mods to exclude from the server pack.
        minecraftVersion - The Minecraft version the modpack uses.
        destination - The destination where the files should be copied to.
        modloader - The modloader used for mod sideness detection.
      • getImprovedFabricLauncher

         final Unit getImprovedFabricLauncher(String minecraftVersion, String fabricVersion, String destination)

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

        Parameters:
        minecraftVersion - The Minecraft version the modpack uses and the Fabric Server Launcher should be downloaded for.
        fabricVersion - The modloader version the modpack uses and the Fabric Server Launcher should be downloaded for.
        destination - The destination of the server pack.
      • copyIcon

         final Unit copyIcon(String destination, String pathToServerIcon)

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

        Parameters:
        destination - The destination where the icon should be copied to.
        pathToServerIcon - The path to the custom server-icon.
      • copyProperties

         final Unit copyProperties(String destination, String pathToServerProperties)

        Copies the server.properties into server pack.

        Parameters:
        destination - The destination where the properties should be copied to.
        pathToServerProperties - The path to the custom server.properties.
      • createServerRunFiles

         final Unit createServerRunFiles(HashMap<String, String> scriptSettings, String destination, Boolean isLocal)

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

        Parameters:
        scriptSettings - Key-value pairs to replace in the script.
        destination - The destination where the scripts should be created in.
        isLocal - Whether the start scripts should be created for a locally usable server pack.
      • zipBuilder

         final Optional<File> zipBuilder(String minecraftVersion, String destination, String modloader, String modloaderVersion)

        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.

        Parameters:
        minecraftVersion - Determines the name of the Minecraft server JAR to exclude from the ZIP-archive if the modloader is Forge.
        destination - The destination where the ZIP-archive should be created in.
        modloader - The modloader the modpack and server pack use.
        modloaderVersion - The modloader version the modpack and server pack use.
      • preInstallationCleanup

         final Unit preInstallationCleanup(String destination)

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

        Parameters:
        destination - The folder in which to perform the cleanup operations.
      • getExplicitFiles

         final List<ServerPackFile> getExplicitFiles(String source, String destination, String modpackDir, String serverPackDestination)

        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.

        Parameters:
        source - source-file/directory
        destination - destination-file/directory
        modpackDir - The modpack-directory.
        serverPackDestination - The destination, normally the server pack-directory.
        Returns:

        List of ServerPackFile.

      • getSaveFiles

         final List<ServerPackFile> getSaveFiles(String clientDir, String directory, String destination)

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

        Parameters:
        clientDir - Target directory in the server pack.
        directory - The save-directory.
        destination - The destination of the server pack.
        Returns:

        List of ServerPackFile which will be included in the server pack.

      • compileModList

         final Pair<List<File>, List<File>> compileModList(PackConfig packConfig)

        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.

        Parameters:
        packConfig - The configurationModel containing the modpack directory, list of clientside-only mods to exclude, Minecraft version used by the modpack and server pack and the modloader used by the modpack and server pack.
        Returns:

        A list of all mods to include in the server pack.

      • compileModList

         final Pair<List<File>, List<File>> compileModList(String modsDir, List<String> exclusionStrings, List<String> whitelistStrings, String minecraftVersion, String modloader)

        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.

        Parameters:
        modsDir - The mods-directory of the modpack of which to generate a list of all its contents.
        exclusionStrings - A list of all clientside-only mods.
        whitelistStrings - A list of mods to include regardless if a match was found in exclusionStrings.
        minecraftVersion - The Minecraft version the modpack uses.
        modloader - The modloader the modpack uses.
        Returns:

        A list of all mods to include in the server pack.

      • getDirectoryFiles

         final List<ServerPackFile> getDirectoryFiles(String source, String destination)

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

        Parameters:
        source - The source-directory.
        destination - The server pack-directory.
        Returns:

        List of files and folders of the server pack.

      • excludeFileOrDirectory

         final Boolean excludeFileOrDirectory(String modpackDir, File fileToCheckFor, List<Regex> exclusions)

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

        Parameters:
        modpackDir - The directory where the modpack resides in.
        fileToCheckFor - The file or directory to check whether it should be excluded from the server pack.
        exclusions - Files or directories determined by ServerPackCreator to be excluded from the server pack
        Returns:

        true if the file or directory was determined to be excluded from the server pack.

      • serverDownloadable

         final Boolean serverDownloadable(String mcVersion, String modloader, String modloaderVersion)

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

        Parameters:
        mcVersion - The Minecraft version.
        modloader - The modloader.
        modloaderVersion - The modloader version.
        Returns:

        true if the installer can be downloaded.

      • postInstallCleanup

         final Unit postInstallCleanup(String destination)

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

        Parameters:
        destination - The destination where we should clean up in.
      • regexWalk

         final Unit regexWalk(File source, String destination, Regex regex, List<ServerPackFile> serverPackFiles)

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

        Parameters:
        source - The source-directory to walk through and perform regex-matches in.
        destination - The destination-directory where a matched file should be copied to, usually the server pack directory.
        regex - Regex with which to perform matches against files in the source-directory.
        serverPackFiles - List of files to copy to the server pack to which any matched file will be added to.