Class ConfigurationHandler
-
- All Implemented Interfaces:
public final class ConfigurationHandlerCheck 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.
Griefed
-
-
Field Summary
Fields Modifier and Type Field Description private final KotlinLoggerlogprivate final Regexforgeprivate final RegexneoForgeprivate final Regexfabricprivate final Regexquiltprivate final RegexlegacyFabricprivate final Regexwhitespaceprivate final Regexpreviousprivate final RegexzipCheckprivate final ModloaderValidatormodloaderValidatorprivate final InclusionsValidatorinclusionsValidatorprivate final ModpackDirectoryValidatormodpackDirectoryValidatorprivate final ModpackZipInspectorzipInspectorprivate final ModpackManifestParsermanifestParser
-
Constructor Summary
Constructors Constructor Description ConfigurationHandler(VersionMeta versionMeta, ApiProperties apiProperties, Utilities utilities, ApiPlugins apiPlugins)
-
Method Summary
Modifier and Type Method Description final KotlinLoggergetLog()final RegexgetForge()final RegexgetNeoForge()final RegexgetFabric()final RegexgetQuilt()final RegexgetLegacyFabric()final RegexgetWhitespace()final RegexgetPrevious()final RegexgetZipCheck()final ModloaderValidatorgetModloaderValidator()final InclusionsValidatorgetInclusionsValidator()final ModpackDirectoryValidatorgetModpackDirectoryValidator()final ModpackZipInspectorgetZipInspector()final ModpackManifestParsergetManifestParser()final UnitaddEventListener(SPCGenericListener genericEventListener)Register a listener notified when a configuration check finishes, regardless of outcome. final UnitaddEventListener(SPCConfigCheckListener configEventListener)Register a listener that receives the check's ConfigCheck result, so a host can react to the details. final ConfigCheckcheckConfiguration(File configFile, PackConfig packConfig, ConfigCheck configCheck, Boolean quietCheck)Check the passed configuration-file. final ConfigCheckcheckConfiguration(PackConfig packConfig, ConfigCheck configCheck, Boolean quietCheck)Check the passed packConfig. final UnitcheckForProjectInformation(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). final ConfigCheckcheckModloader(String modloader, ConfigCheck configCheck)Checks whether a supported modloader was specified. final UnitsanitizeLinks(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. final BooleancheckIconAndProperties(String iconOrPropertiesPath)Checks the passed String whether it is an existing file. final ConfigCheckisDir(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 truepath to Java executable/binary, Minecraft version, modloader and modloader version.final ConfigCheckisZip(PackConfig packConfig, ConfigCheck configCheck)Checks the specified ZIP-archive for validity. final ConfigCheckcheckModloaderVersion(String modloader, String modloaderVersion, String minecraftVersion, ConfigCheck configCheck)Check the given Minecraft- and modloader-versions for the specified modloader. final UnitprintConfigurationModel(PackConfig packConfig)Convenience method which passes the important fields from an instance of PackConfig to . final UnitprintConfigurationModel(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. final UnitprintEncounteredErrors(List<String> encounteredErrors)Print all encountered errors to logs. final UnitensureScriptSettingsDefaults(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 createdSPC_MINECRAFT_VERSION_SPC:Minecraft version of the modpack` *SPC_MODLOADER_SPC:The modloader of the modpackSPC_MODLOADER_VERSION_SPC:The modloader version of the modpack*SPC_JAVA_ARGS_SPC:The JVM args to be used to run the serverSPC_JAVA_SPC:Path to the java installation to be used to run the serverSPC_FABRIC_INSTALLER_VERSION_SPC:Most recent version of the Fabric installer at the time of creating the scriptsSPC_QUILT_INSTALLER_VERSION_SPC:Most recent version of the Quilt installer at the time of creating the scripts
final ConfigCheckcheckInclusions(List<InclusionSpecification> inclusions, String modpackDir, ConfigCheck configCheck, Boolean printLog)Check the inclusion-specifications for existing sources, valid destinations and valid in-/exclusion-filter regexes. final ConfigCheckcheckZipArchive(String pathToZip, ConfigCheck configCheck)Check a given ZIP-archives contents for validity as a modpack. final StringunzipDestination(String destination)Update the destination to which the ZIP-archive will be extracted, based on whether a directory of the same name already exists. 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. final StringcheckManifests(String destination, PackConfig packConfig, ConfigCheck configCheck)Check whether various manifests from various launchers exist and use them to update the PackConfig and pack-name. final List<File>manifestCandidates(String destination)Every launcher-manifest checkManifests looks for in destination, existing or not. final List<String>getDirectoriesInModpackZipBaseDirectory(File zipFile)Acquire a list of all directories in the base-directory of a ZIP-file. final UnitupdateConfigModelFromCurseManifest(PackConfig packConfig, File manifest)Update the given PackConfig with values from a CurseForge manifest.json. final StringupdatePackName(PackConfig packConfig, String childNodes)Acquire the modpacks name from the modpack-JSON stored in the PackConfig. final UnitupdateConfigModelFromMinecraftInstance(PackConfig packConfig, File minecraftInstance)Update the given PackConfig with values from a CurseForge minecraftinstance.json. final UnitupdateConfigModelFromModrinthManifest(PackConfig packConfig, File manifest)Update the given PackConfig with values from a Modrinth modrinth.index.json. final UnitupdateConfigModelFromATLauncherInstance(PackConfig packConfig, File manifest)Update the given PackConfig with values from an ATLauncher instance.json. final UnitupdateConfigModelFromConfigJson(PackConfig packConfig, File config)Update the given PackConfig with values from a GDLauncher config.json. final UnitupdateConfigModelFromGDInstanceJson(PackConfig packConfig, File instance)Update the given PackConfig with values from a GDLauncher instance.json in the modpacks parent-directory. final UnitupdateConfigModelFromMMCPack(PackConfig packConfig, File mmcPack)Update the given PackConfig with values from a MultiMC/Prism mmc-pack.json. final StringupdateDestinationFromInstanceCfg(File instanceCfg)Acquire the instance-name from a MultiMC/Prism instance.cfg. final StringgetModLoaderCase(String modloader)Normalize the modloader-name to first-letter-uppercase, defaulting to Forge for unknown loaders. final ConfigCheckcheckModpackDir(String modpackDir, ConfigCheck configCheck, Boolean printLog)Check the passed directory for existence, type and the absence of the overrides-directory. final List<String>getAllFilesAndDirectoriesInModpackZip(File zipFile)Acquire a list of all files and directories in a ZIP-file. final List<String>getDirectoriesInModpackZip(File zipFile)Acquire a list of all directories in a ZIP-file, excluding files. final List<String>getFilesInModpackZip(File zipFile)Acquire a list of all files in a ZIP-file, excluding directories. final PackConfiggenerateConfigFromModpack(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. -
-
Constructor Detail
-
ConfigurationHandler
ConfigurationHandler(VersionMeta versionMeta, ApiProperties apiProperties, Utilities utilities, ApiPlugins apiPlugins)
- Parameters:
versionMeta- Meta used for Minecraft and modloader version checks and verification.apiProperties- Base settings of SPC used just about everywhere.utilities- Common utilities used all across SPC.apiPlugins- Addons and extensions added by external addons which can add additional checks to a given configuration check.
-
-
Method Detail
-
getLog
final KotlinLogger getLog()
-
getNeoForge
final Regex getNeoForge()
-
getLegacyFabric
final Regex getLegacyFabric()
-
getWhitespace
final Regex getWhitespace()
-
getPrevious
final Regex getPrevious()
-
getZipCheck
final Regex getZipCheck()
-
getModloaderValidator
final ModloaderValidator getModloaderValidator()
-
getInclusionsValidator
final InclusionsValidator getInclusionsValidator()
-
getModpackDirectoryValidator
final ModpackDirectoryValidator getModpackDirectoryValidator()
-
getZipInspector
final ModpackZipInspector getZipInspector()
-
getManifestParser
final ModpackManifestParser getManifestParser()
-
addEventListener
final Unit addEventListener(SPCGenericListener genericEventListener)
Register a listener notified when a configuration check finishes, regardless of outcome.
-
addEventListener
final Unit addEventListener(SPCConfigCheckListener configEventListener)
Register a listener that receives the check's ConfigCheck result, so a host can react to the details.
-
checkConfiguration
final ConfigCheck checkConfiguration(File configFile, PackConfig packConfig, ConfigCheck configCheck, Boolean quietCheck)
Check the passed configuration-file. If any check returns
truethen 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.- Parameters:
configFile- The configuration file to check.packConfig- Instance of a configuration of a modpack.configCheck- Contains all encountered errors during the check of the passed configuration.quietCheck- Whether the configuration should be printed to the console and logs.- Returns:
falseif the configuration has passed all tests.
-
checkConfiguration
final ConfigCheck checkConfiguration(PackConfig packConfig, ConfigCheck configCheck, Boolean quietCheck)
Check the passed packConfig. If any check returns
truethen 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.
- Parameters:
packConfig- Instance of a configuration of a modpack.configCheck- Contains all encountered errors during the check of the passed configuration.quietCheck- Whether the configuration should be printed to the console and logs.- Returns:
falseif 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).
-
checkModloader
final ConfigCheck checkModloader(String modloader, ConfigCheck configCheck)
Checks whether a supported modloader was specified.
-
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.
- Parameters:
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.
- Parameters:
iconOrPropertiesPath- The path to the custom server-icon.png or server.properties file to check.- Returns:
trueif 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
truepath to Java executable/binary, Minecraft version, modloader and modloader version.- Parameters:
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:
trueif 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
modsandconfigfolders at minimum. If any ofmanifest.json,minecraftinstance.jsonorconfig.jsonare available, gather as much information from them as possible.- Parameters:
packConfig- Instance of PackConfig with a server pack configuration.configCheck- Collection of encountered errors, if any, for convenient result-checks.- Returns:
falsewhen no errors were encountered.
-
checkModloaderVersion
final ConfigCheck checkModloaderVersion(String modloader, String modloaderVersion, String minecraftVersion, ConfigCheck configCheck)
Check the given Minecraft- and modloader-versions for the specified modloader.
-
printConfigurationModel
final Unit printConfigurationModel(PackConfig packConfig)
Convenience method which passes the important fields from an instance of PackConfig to .printConfigurationModel
- Parameters:
packConfig- Instance of PackConfig to print to console and logs.
-
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.
- Parameters:
modpackDirectory- The used modpackDir field either from a configuration file or from configuration setup.clientsideMods- List of clientside-only mods to exclude from the server pack...inclusions- List of directories in the modpack which are to be included in the server pack.minecraftVer- The Minecraft version the modpack uses.modloader- The modloader the modpack uses.modloaderVersion- The version of the modloader the modpack uses.includeIcon- Whether to include the server-icon.png in the server pack.includeProperties- Whether to include the server.properties in the server pack.includeZip- Whether to create a zip-archive of the server pack, excluding the Minecraft server JAR according to Mojang's TOS and EULA.javaArgs- Java arguments to write the start-scripts with.serverPackSuffix- Suffix to append to name of the server pack to be generated.serverIconPath- The path to the custom server-icon.png to be used in the server pack.serverPropertiesPath- The path to the custom server.properties to be used in the server pack.scriptSettings- Custom settings for start script creation.
-
printEncounteredErrors
final Unit printEncounteredErrors(List<String> encounteredErrors)
Print all encountered errors to logs.
- Parameters:
encounteredErrors- A list of all errors which were encountered during a configuration check.
-
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 createdSPC_MINECRAFT_VERSION_SPC:Minecraft version of the modpack` *SPC_MODLOADER_SPC:The modloader of the modpackSPC_MODLOADER_VERSION_SPC:The modloader version of the modpack*SPC_JAVA_ARGS_SPC:The JVM args to be used to run the serverSPC_JAVA_SPC:Path to the java installation to be used to run the serverSPC_FABRIC_INSTALLER_VERSION_SPC:Most recent version of the Fabric installer at the time of creating the scriptsSPC_QUILT_INSTALLER_VERSION_SPC:Most recent version of the Quilt installer at the time of creating the scripts
- Parameters:
packConfig- Model in which to ensure the default key-value pairs are present.
-
checkInclusions
final ConfigCheck checkInclusions(List<InclusionSpecification> inclusions, String modpackDir, ConfigCheck configCheck, Boolean printLog)
Check the inclusion-specifications for existing sources, valid destinations and valid in-/exclusion-filter regexes.
-
checkZipArchive
final ConfigCheck checkZipArchive(String pathToZip, ConfigCheck configCheck)
Check a given ZIP-archives contents for validity as a modpack.
-
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
- Parameters:
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.
-
checkManifests
final String checkManifests(String destination, PackConfig packConfig, ConfigCheck configCheck)
Check whether various manifests from various launchers exist and use them to update the PackConfig and pack-name.
-
manifestCandidates
final List<File> manifestCandidates(String destination)
Every launcher-manifest checkManifests looks for in destination, existing or not. Reads ModpackManifestParser.manifestCandidates rather than holding its own copy, so the published facade and the list actually consulted cannot drift apart.
-
getDirectoriesInModpackZipBaseDirectory
final List<String> getDirectoriesInModpackZipBaseDirectory(File zipFile)
Acquire a list of all directories in the base-directory of a ZIP-file.
-
updateConfigModelFromCurseManifest
final Unit updateConfigModelFromCurseManifest(PackConfig packConfig, File manifest)
Update the given PackConfig with values from a CurseForge manifest.json.
-
updatePackName
final String updatePackName(PackConfig packConfig, String childNodes)
Acquire the modpacks name from the modpack-JSON stored in the PackConfig.
-
updateConfigModelFromMinecraftInstance
final Unit updateConfigModelFromMinecraftInstance(PackConfig packConfig, File minecraftInstance)
Update the given PackConfig with values from a CurseForge minecraftinstance.json.
-
updateConfigModelFromModrinthManifest
final Unit updateConfigModelFromModrinthManifest(PackConfig packConfig, File manifest)
Update the given PackConfig with values from a Modrinth modrinth.index.json.
-
updateConfigModelFromATLauncherInstance
final Unit updateConfigModelFromATLauncherInstance(PackConfig packConfig, File manifest)
Update the given PackConfig with values from an ATLauncher instance.json.
-
updateConfigModelFromConfigJson
final Unit updateConfigModelFromConfigJson(PackConfig packConfig, File config)
Update the given PackConfig with values from a GDLauncher config.json.
-
updateConfigModelFromGDInstanceJson
final Unit updateConfigModelFromGDInstanceJson(PackConfig packConfig, File instance)
Update the given PackConfig with values from a GDLauncher instance.json in the modpacks parent-directory.
-
updateConfigModelFromMMCPack
final Unit updateConfigModelFromMMCPack(PackConfig packConfig, File mmcPack)
Update the given PackConfig with values from a MultiMC/Prism mmc-pack.json.
-
updateDestinationFromInstanceCfg
final String updateDestinationFromInstanceCfg(File instanceCfg)
Acquire the instance-name from a MultiMC/Prism instance.cfg.
-
getModLoaderCase
final String getModLoaderCase(String modloader)
Normalize the modloader-name to first-letter-uppercase, defaulting to Forge for unknown loaders.
-
checkModpackDir
final ConfigCheck checkModpackDir(String modpackDir, ConfigCheck configCheck, Boolean printLog)
Check the passed directory for existence, type and the absence of the overrides-directory.
-
getAllFilesAndDirectoriesInModpackZip
final List<String> getAllFilesAndDirectoriesInModpackZip(File zipFile)
Acquire a list of all files and directories in a ZIP-file.
-
getDirectoriesInModpackZip
final List<String> getDirectoriesInModpackZip(File zipFile)
Acquire a list of all directories in a ZIP-file, excluding files.
-
getFilesInModpackZip
final List<String> getFilesInModpackZip(File zipFile)
Acquire a list of all files in a ZIP-file, excluding directories.
-
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.
- Parameters:
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.
-
-
-