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 RegexzipCheck
-
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 UnitaddEventListener(SPCGenericListener genericEventListener)final UnitaddEventListener(SPCConfigCheckListener configEventListener)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 either Forge or Fabric were specified as the modloader. 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<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)Checks whether the passed list of directories which are supposed to be in the modpack directory is empty, or whether all directories in the list exist in the modpack directory. final ConfigCheckcheckZipArchive(String pathToZip, ConfigCheck configCheck)Check a given ZIP-archives contents. final StringunzipDestination(String destination)Update the destination to which the ZIP-archive will the extracted to, 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 our ConfigurationModel and pack name. final List<String>getDirectoriesInModpackZipBaseDirectory(File zipFile)Acquire a list of directories in the base-directory of a ZIP-file. final UnitupdateConfigModelFromCurseManifest(PackConfig packConfig, File manifest)manifest.jsonUpdate the given ConfigurationModel with values gathered from the downloaded CurseForge modpack.final StringupdatePackName(PackConfig packConfig, String childNodes)Acquire the modpacks name from the JSON previously acquired and stored in the ConfigurationModel. final UnitupdateConfigModelFromMinecraftInstance(PackConfig packConfig, File minecraftInstance)minecraftinstance.jsonUpdate the given ConfigurationModel with values gathered from the minecraftinstance.json of the modpack.final UnitupdateConfigModelFromModrinthManifest(PackConfig packConfig, File manifest)modrinth.index.jsonUpdate the given ConfigurationModel with values gathered from a Modrinthmodrinth.index.json-manifest.final UnitupdateConfigModelFromATLauncherInstance(PackConfig packConfig, File manifest)instance.jsonUpdate the given ConfigurationModel with values gathered from a ATLauncher manifest.final UnitupdateConfigModelFromConfigJson(PackConfig packConfig, File config)config.jsonUpdate the given ConfigurationModel with values gathered from the modpacks config.json.final UnitupdateConfigModelFromGDInstanceJson(PackConfig packConfig, File instance)parentDirectory/instance.jsonUpdate the given PackConfig with values gathered from the modpacks instance.json.final UnitupdateConfigModelFromMMCPack(PackConfig packConfig, File mmcPack)mmc-pack.jsonUpdate the given ConfigurationModel with values gathered from the modpacks mmc-pack.json.final StringupdateDestinationFromInstanceCfg(File instanceCfg)instance.cfgAcquire the name of the modpack/instance of a MultiMC modpack from the modpacks instance.cfg, which is usually created by the MultiMC launcher.final StringgetModLoaderCase(String modloader)Ensures the modloader is normalized to first letter upper case and rest lower case. final ConfigCheckcheckModpackDir(String modpackDir, ConfigCheck configCheck, Boolean printLog)Check the passed directory for existence and whether it is a directory, rather than a file. 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. final List<String>getFilesInModpackZip(File zipFile)Acquire a list of all files in a ZIP-file. 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()
-
addEventListener
final Unit addEventListener(SPCGenericListener genericEventListener)
-
addEventListener
final Unit addEventListener(SPCConfigCheckListener configEventListener)
-
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 either Forge or Fabric were specified as the modloader.
- Parameters:
modloader- Check as case-insensitive for Forge or Fabric.- Returns:
trueif the specified modloader is either Forge or Fabric. False if neither.
-
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.
- Parameters:
modloader- The passed modloader which determines whether the check for Forge or Fabric is called.modloaderVersion- The version of the modloader which is checked against the corresponding modloader's manifest.minecraftVersion- The version of Minecraft used for checking the Forge version.- Returns:
trueif the specified modloader version was found in the corresponding manifest.
-
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<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)
Checks whether the passed list of directories which are supposed to be in the modpack directory is empty, or whether all directories in the list exist in the modpack directory. If the user specified a
source/file;destination/file-combination, it is checked whether the specified source-file exists on the host.- Parameters:
inclusions- Directories, orsource/file;destination/file-combinations, to check for existence.modpackDir- Path to the modpack directory in which to check for existence of the passed list of directories.- Returns:
trueif every directory was found in the modpack directory. If any single one was not found, false is returned.
-
checkZipArchive
final ConfigCheck checkZipArchive(String pathToZip, ConfigCheck configCheck)
Check a given ZIP-archives contents. If the ZIP-archive only contains one directory, or if it contains neither the mods nor the config directories, consider it invalid.
- Parameters:
pathToZip- Path to the ZIP-file to check.
-
unzipDestination
final String unzipDestination(String destination)
Update the destination to which the ZIP-archive will the extracted to, based on whether a directory of the same name already exists.
- Parameters:
destination- The destination to where the ZIP-archive was about to be extracted to.- Returns:
The destination where the ZIP-archive will be extracted to.
-
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 our ConfigurationModel and pack name.
- Parameters:
destination- The destination in which the manifests are.packConfig- The ConfigurationModel to update.configCheck- Collection of encountered errors, if any, for convenient result-checks.- Returns:
The name of the modpack currently being checked.
nullif the name could not be acquired.
-
getDirectoriesInModpackZipBaseDirectory
final List<String> getDirectoriesInModpackZipBaseDirectory(File zipFile)
Acquire a list of directories in the base-directory of a ZIP-file.
- Parameters:
zipFile- The ZIP-archive to get the list of files from.- Returns:
All directories in the base-directory of the ZIP-file.
-
updateConfigModelFromCurseManifest
final Unit updateConfigModelFromCurseManifest(PackConfig packConfig, File manifest)
manifest.jsonUpdate the given ConfigurationModel with values gathered from the downloaded CurseForge modpack. A manifest.json-file is usually created when a modpack is exported through launchers like Overwolf's CurseForge or GDLauncher.
- Parameters:
packConfig- An instance containing a configuration for a modpack from which to create a server pack.manifest- The CurseForge manifest.json-file of the modpack to read.
-
updatePackName
final String updatePackName(PackConfig packConfig, String childNodes)
Acquire the modpacks name from the JSON previously acquired and stored in the ConfigurationModel.
- Parameters:
packConfig- The ConfigurationModel containing the JsonNode from which to acquire the modpacks name.childNodes- The child nodes, in order, which contain the requested packname.- Returns:
The new name of the modpack.
-
updateConfigModelFromMinecraftInstance
final Unit updateConfigModelFromMinecraftInstance(PackConfig packConfig, File minecraftInstance)
minecraftinstance.jsonUpdate the given ConfigurationModel with values gathered from the minecraftinstance.json of the modpack. A minecraftinstance.json is usually created by Overwolf's CurseForge launcher.
- Parameters:
packConfig- An instance containing a configuration for a modpack from which to create a server pack.minecraftInstance- The minecraftinstance.json-file of the modpack to read.
-
updateConfigModelFromModrinthManifest
final Unit updateConfigModelFromModrinthManifest(PackConfig packConfig, File manifest)
modrinth.index.jsonUpdate the given ConfigurationModel with values gathered from a Modrinth
modrinth.index.json-manifest.- Parameters:
packConfig- The model to update.manifest- The manifest file.
-
updateConfigModelFromATLauncherInstance
final Unit updateConfigModelFromATLauncherInstance(PackConfig packConfig, File manifest)
instance.jsonUpdate the given ConfigurationModel with values gathered from a ATLauncher manifest.
- Parameters:
packConfig- The model to update.manifest- The manifest file.
-
updateConfigModelFromConfigJson
final Unit updateConfigModelFromConfigJson(PackConfig packConfig, File config)
config.jsonUpdate the given ConfigurationModel with values gathered from the modpacks config.json. A config.json is usually created by GDLauncher.
- Parameters:
packConfig- An instance containing a configuration for a modpack from which to create a server pack.config- The config.json-file of the modpack to read.
-
updateConfigModelFromGDInstanceJson
final Unit updateConfigModelFromGDInstanceJson(PackConfig packConfig, File instance)
parentDirectory/instance.jsonUpdate the given PackConfig with values gathered from the modpacks instance.json. An instance.json is usually created by GDLauncher and located in the modpacks parent directory of the data-directory.
- Parameters:
packConfig- An instance containing a configuration for a modpack from which to create a server pack.instance- The instance.json-file of the modpack to read.
-
updateConfigModelFromMMCPack
final Unit updateConfigModelFromMMCPack(PackConfig packConfig, File mmcPack)
mmc-pack.jsonUpdate the given ConfigurationModel with values gathered from the modpacks mmc-pack.json. A mmc-pack.json is usually created by the MultiMC launcher.
- Parameters:
packConfig- An instance containing a configuration for a modpack from which to create a server pack.mmcPack- The config.json-file of the modpack to read.
-
updateDestinationFromInstanceCfg
final String updateDestinationFromInstanceCfg(File instanceCfg)
instance.cfgAcquire the name of the modpack/instance of a MultiMC modpack from the modpacks instance.cfg, which is usually created by the MultiMC launcher.
- Parameters:
instanceCfg- The config.json-file of the modpack to read.- Returns:
The instance name.
-
getModLoaderCase
final String getModLoaderCase(String modloader)
Ensures the modloader is normalized to first letter upper case and rest lower case. Basically allows the user to input Forge or Fabric in any combination of upper- and lowercase and ServerPackCreator will still be able to work with the users input.
- Parameters:
modloader- Modloader String-representation to normalize.- Returns:
A normalized String of the specified modloader.
-
checkModpackDir
final ConfigCheck checkModpackDir(String modpackDir, ConfigCheck configCheck, Boolean printLog)
Check the passed directory for existence and whether it is a directory, rather than a file.
- Parameters:
modpackDir- The modpack directory.configCheck- Collection of encountered errors, if any, for convenient result-checks.- Returns:
trueif the directory exists.
-
getAllFilesAndDirectoriesInModpackZip
final List<String> getAllFilesAndDirectoriesInModpackZip(File zipFile)
Acquire a list of all files and directories in a ZIP-file.
- Parameters:
zipFile- The ZIP-archive to get the list of files from.- Returns:
All files and directories in the ZIP-file.
-
getDirectoriesInModpackZip
final List<String> getDirectoriesInModpackZip(File zipFile)
Acquire a list of all directories in a ZIP-file. The resulting list excludes files.
- Parameters:
zipFile- The ZIP-archive to get the list of files from.- Returns:
All directories in the ZIP-file.
-
getFilesInModpackZip
final List<String> getFilesInModpackZip(File zipFile)
Acquire a list of all files in a ZIP-file. The resulting list excludes directories.
- Parameters:
zipFile- The ZIP-archive to get the list of files from.- Returns:
All files in the ZIP-file.
-
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.
-
-
-