Class ConfigurationHandler

  • All Implemented Interfaces:

    
    public final class ConfigurationHandler
    
                        

    Check any given PackConfig for errors and, if so desired, add them to a passed list of errors, so you may display them in a GUI, CLI or website. The most important method is checkConfiguration and all of its variants which will check your passed configuration model for errors, indicating whether it is safe to use for further operations. Running your model through the checks also ensures that the default script settings are present and set according to your pack's environment.

    Author:

    Griefed

    • Method Detail

      • getLog

         final KotlinLogger getLog()

        Logger for check results, exposed because the checks report through it rather than returning text.

      • getForge

         final Regex getForge()

        Loader-name matcher for Forge, from the single source of truth in SupportedModloaders.

      • getNeoForge

         final Regex getNeoForge()

        Loader-name matcher for NeoForge. Tested before forge, whose pattern also matches neoforge.

      • getLegacyFabric

         final Regex getLegacyFabric()

        Loader-name matcher for LegacyFabric. Tested before fabric, which would otherwise swallow it.

      • getWhitespace

         final Regex getWhitespace()

        Matches a string that is only whitespace, so a blank-but-not-empty value is rejected as unset.

      • getPrevious

         final Regex getPrevious()

        Matches a server pack directory that already carries a numeric suffix, so the next one increments.

      • getZipCheck

         final Regex getZipCheck()

        Matches a ZIP entry that is a bare top-level directory — see ModpackZipInspector.zipCheck, which owns the pattern. Read through rather than copied, so this published constant cannot drift from the one inspection actually uses. Computed on access because zipInspector is declared after this property, and a plain initialiser would read it before it exists.

      • checkConfiguration

         final ConfigCheck checkConfiguration(File configFile, PackConfig packConfig, ConfigCheck configCheck, Boolean quietCheck)

        Check the passed configuration-file. If any check returns true then the server pack will not be created. In order to find out which check failed, the user has to check their serverpackcreator.log in the logs-directory.

        configFile — The configuration file to check. Must either be an existing file to load a configuration from or null if you want to use the passed configuration model. packConfig — Instance of a configuration of a modpack. Can be used to further display or use any information within, as it may be changed or otherwise altered by this method. configCheck — Contains all encountered errors during the check of the passed configuration. quietCheck — Whether the configuration should be printed to the console and logs. Pass false to quietly check the configuration.

      • checkConfiguration

         final ConfigCheck checkConfiguration(PackConfig packConfig, ConfigCheck configCheck, Boolean quietCheck)

        Check the passed packConfig. If any check returns true then the server pack will not be created. In order to find out which check failed, the user has to check their serverpackcreator.log in the logs-directory.

        The passed packConfig can be used to further display or use any information within, as it may be changed or otherwise altered by this method.

        packConfig — Instance of a configuration of a modpack. Can be used to further display or use any information within, as it may be changed or otherwise altered by this method. configCheck — Contains all encountered errors during the check of the passed configuration. quietCheck — Whether the configuration should be printed to the console and logs. Pass false to quietly check the configuration. Returns false if all checks are passed.

      • checkForProjectInformation

         final Unit checkForProjectInformation(PackConfig packConfig)

        Check for minecraftinstance.json and profile.json and if either is present, try to obtain the project- and fileIDs as well as the modpack distribution-platform (Modrinth or CurseForge).

      • sanitizeLinks

         final Unit sanitizeLinks(PackConfig packConfig)

        Sanitize any and all links in a given instance of PackConfig modpack-directory, server-icon path, server-properties path, Java path and copy-directories entries.

        packConfig — Instance of PackConfig in which to sanitize links to their respective destinations.

      • checkIconAndProperties

         final Boolean checkIconAndProperties(String iconOrPropertiesPath)

        Checks the passed String whether it is an existing file. If the passed String is empty, then ServerPackCreator will treat it as the user being fine with the default files and return the corresponding boolean.

        iconOrPropertiesPath — The path to the custom server-icon.png or server.properties file to check. Returns true if the file exists or an empty String was passed, false if a file was specified, but the file was not found.

      • isDir

         final ConfigCheck isDir(PackConfig packConfig, ConfigCheck configCheck)

        If the in the configuration specified modpack dir is an existing directory, checks are made for valid configuration of: directories to copy to server pack, if includeServerInstallation is true path to Java executable/binary, Minecraft version, modloader and modloader version.

        packConfig — An instance of PackConfig which contains the configuration of the modpack. configCheck — Contains all encountered errors during the check of the passed configuration. Returns true if an error is found during configuration check.

      • isZip

         final ConfigCheck isZip(PackConfig packConfig, ConfigCheck configCheck)

        Checks the specified ZIP-archive for validity. In order for a modpack ZIP-archive to be considered valid, it needs to contain the mods and config folders at minimum. If any of manifest.json, minecraftinstance.json or config.json are available, gather as much information from them as possible.

        packConfig — Instance of PackConfig with a server pack configuration. configCheck — Collection of encountered errors, if any, for convenient result-checks. Returns false when no errors were encountered.

      • printConfigurationModel

         final Unit printConfigurationModel(String modpackDirectory, List<String> clientsideMods, List<String> modsWhitelist, List<InclusionSpecification> inclusions, String minecraftVer, String modloader, String modloaderVersion, Boolean includeIcon, Boolean includeProperties, Boolean includeZip, String javaArgs, String serverPackSuffix, String serverIconPath, String serverPropertiesPath, HashMap<String, String> scriptSettings)

        Prints all passed fields to the console and serverpackcreator.log. Used to show the user the configuration before ServerPackCreator starts the generation of the server pack or, if checks failed, to show the user their last configuration, so they can more easily identify problems with said configuration.

        Should a user report an issue on GitHub and include their logs (which I hope they do....), this would also help me help them. Logging is good. People should use more logging.

      • ensureScriptSettingsDefaults

         final Unit ensureScriptSettingsDefaults(PackConfig packConfig)

        Update the script settings and ensure the default keys, with values gathered from the passed PackConfig, are present:

        • SPC_SERVERPACKCREATOR_VERSION_SPC : ServerPackCreator version with which the scripts were created

        • SPC_MINECRAFT_VERSION_SPC : Minecraft version of the modpack ` *

        • SPC_MODLOADER_SPC : The modloader of the modpack

        • SPC_MODLOADER_VERSION_SPC : The modloader version of the modpack *

        • SPC_JAVA_ARGS_SPC : The JVM args to be used to run the server

        • SPC_JAVA_SPC : Path to the java installation to be used to run the server

        • SPC_FABRIC_INSTALLER_VERSION_SPC : Most recent version of the Fabric installer at the time of creating the scripts

        • SPC_QUILT_INSTALLER_VERSION_SPC : Most recent version of the Quilt installer at the time of creating the scripts

        packConfig — Model in which to ensure the default key-value pairs are present.

      • unzipDestination

         final String unzipDestination(String destination)

        Update the destination to which the ZIP-archive will be extracted, based on whether a directory of the same name already exists.

      • suggestInclusions

         final ArrayList<InclusionSpecification> suggestInclusions(String modpackDir)

        Creates a list of suggested directories to include in server pack which is later on written to a new configuration file. The list of directories to include in the server pack which is generated by this method excludes well know directories which would not be needed by a server pack. If you have suggestions to this list, open a feature request issue on GitHub

        modpackDir — The directory for which to gather a list of directories to copy to the server pack. Returns directories inside the modpack, excluding well known client-side only directories.

      • getModLoaderCase

         final String getModLoaderCase(String modloader)

        Normalize the modloader-name to first-letter-uppercase, defaulting to Forge for unknown loaders.

      • generateConfigFromModpack

         final PackConfig generateConfigFromModpack(File modpackDirectory)

        Generate a PackConfig from a modpack-directory, resulting in a basic server pack configuration with default values, for an easy-to-use starting point of a server pack config.

        modpackDirectory — The directory which contains the modpack for which a server pack config should be generated. Returns a PackConfig for the specified modpack. If no manifests were available, then this PackConfig will only contain basic values, like a list of clientside-only mods, but no detected Minecraft version, modloader, or modloader version etc.