Class ServerPackHandler
-
- All Implemented Interfaces:
public final class ServerPackHandlerEverything 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:
getImprovedFabricLauncher if Fabric is the chosen Modloader
If you want to execute extensions, see
Griefed
-
-
Field Summary
Fields Modifier and Type Field Description private final KotlinLoggerlogprivate final List<String>modFileEndingsprivate final ModListCompilermodListCompilerprivate final ServerPackFileGathererfileGathererprivate final ServerPackProvisionerprovisionerprivate final Stringvariables
-
Constructor Summary
Constructors Constructor Description ServerPackHandler(ApiProperties apiProperties, VersionMeta versionMeta, Utilities utilities, ApiPlugins apiPlugins, ModScanner modScanner)
-
Method Summary
Modifier and Type Method Description final KotlinLoggergetLog()final List<String>getModFileEndings()final ModListCompilergetModListCompiler()final ServerPackFileGatherergetFileGatherer()final ServerPackProvisionergetProvisioner()final StringgetVariables()final UnitaddEventListener(SPCGenericListener genericEventListener)Register a listener notified when generation finishes, regardless of outcome. final UnitaddEventListener(SPCPreServerPackGenerationListener preServerPackGenerationListener)Register a listener invoked before generation begins — the hook for preparing or vetoing a run. final UnitaddEventListener(SPCPreServerPackZipListener preServerPackZipListener)Register a listener invoked after the pack is assembled but before it is zipped, to amend its contents. final UnitaddEventListener(SPCPostGenListener postGenListener)Register a listener invoked once everything, zip included, is finished. final StringgetServerPackDestination(PackConfig packConfig)Acquire the destination directory in which the server pack will be generated. final ServerPackGenerationrun(PackConfig packConfig)Create a server pack from a given instance of PackConfig. final UnitcleanupEnvironment(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. final List<File>copyFiles(String modpackDir, ArrayList<InclusionSpecification> inclusions, List<String> clientMods, List<String> whitelist, String minecraftVersion, String destination, String modloader, Boolean overwrite)Recursively copy all specified directories and files, excluding clientside-only mods, to the server pack. final List<ServerPackFile>getServerFiles(InclusionSpecification inclusion, String modpackDir, String destination, List<Regex> exclusions, List<String> clientMods, List<String> modWhitelist, String minecraftVersion, String modloader)Gather the server pack-files for a single inclusion-specification. final UnitgetImprovedFabricLauncher(String minecraftVersion, String fabricVersion, String destination)Download and provide the improved Fabric Server Launcher, if available for the given versions. final UnitcopyIcon(String destination, String pathToServerIcon)Copy the server-icon.png into the server pack, scaled to 64x64. final UnitcopyProperties(String destination, String pathToServerProperties)Copy the server.properties into the server pack. final UnitcreateServerRunFiles(HashMap<String, String> scriptSettings, String destination, Boolean isLocal)Create start-scripts, variables.txt and HOW-TO-RUN.md for the generated server pack. final Optional<File>zipBuilder(String minecraftVersion, String destination, String modloader, String modloaderVersion)Create the ZIP-archive of the server pack, honoring the configured ZIP-exclusions. final UnitpreInstallationCleanup(String destination)Delete configured leftover-files before a modloader-server installation. final List<ServerPackFile>getExplicitFiles(String source, String destination, String modpackDir, String serverPackDestination)Gather all files for an explicit source-destination-combination. final List<ServerPackFile>getSaveFiles(String clientDir, String directory, String destination)Recursively gather all files of the given save-directory. final Pair<List<File>, List<File>>compileModList(PackConfig packConfig)Generate the list of mods to include in the server pack from the given configuration. final Pair<List<File>, List<File>>compileModList(String modsDir, List<String> clientsideModsList, List<String> modWhitelist, String minecraftVersion, String modloader)Generate the list of mods to include in the server pack, excluding clientside-only mods. final List<ServerPackFile>getDirectoryFiles(String source, String destination)Recursively gather all files of the given directory as source-destination-pairs. final BooleanexcludeFileOrDirectory(String modpackDir, File fileToCheckFor, List<Regex> exclusions)Whether the given file or directory matches any of the given exclusion-regexes. final BooleanserverDownloadable(String mcVersion, String modloader, String modloaderVersion)Whether the installer for the given modloader-combination is available/reachable. final UnitpostInstallCleanup(String destination)Delete configured installer-leftovers after a modloader-server installation. final UnitregexWalk(File source, String destination, Regex regex, List<ServerPackFile> serverPackFiles)Gather every file matching the given regex from the source-directory. final StringreplacePlaceholders(Boolean isLocal, String content, HashMap<String, String> scriptSettings)Replace script-placeholders in the given content with their configured values. -
-
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()
-
getModFileEndings
final List<String> getModFileEndings()
-
getModListCompiler
final ModListCompiler getModListCompiler()
-
getFileGatherer
final ServerPackFileGatherer getFileGatherer()
-
getProvisioner
final ServerPackProvisioner getProvisioner()
-
getVariables
final String getVariables()
-
addEventListener
final Unit addEventListener(SPCGenericListener genericEventListener)
Register a listener notified when generation finishes, regardless of outcome.
-
addEventListener
final Unit addEventListener(SPCPreServerPackGenerationListener preServerPackGenerationListener)
Register a listener invoked before generation begins — the hook for preparing or vetoing a run.
-
addEventListener
final Unit addEventListener(SPCPreServerPackZipListener preServerPackZipListener)
Register a listener invoked after the pack is assembled but before it is zipped, to amend its contents.
-
addEventListener
final Unit addEventListener(SPCPostGenListener postGenListener)
Register a listener invoked once everything, zip included, is finished.
-
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.1would becomeSurvive_Create_Prosper_4_-_5.0.1Even 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:
trueif 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)
Recursively copy all specified directories and files, excluding clientside-only mods, to the server pack.
-
getServerFiles
final List<ServerPackFile> getServerFiles(InclusionSpecification inclusion, String modpackDir, String destination, List<Regex> exclusions, List<String> clientMods, List<String> modWhitelist, String minecraftVersion, String modloader)
Gather the server pack-files for a single inclusion-specification.
-
getImprovedFabricLauncher
final Unit getImprovedFabricLauncher(String minecraftVersion, String fabricVersion, String destination)
Download and provide the improved Fabric Server Launcher, if available for the given versions.
-
copyIcon
final Unit copyIcon(String destination, String pathToServerIcon)
Copy the server-icon.png into the server pack, scaled to 64x64.
-
copyProperties
final Unit copyProperties(String destination, String pathToServerProperties)
Copy the server.properties into the server pack.
-
createServerRunFiles
final Unit createServerRunFiles(HashMap<String, String> scriptSettings, String destination, Boolean isLocal)
Create start-scripts, variables.txt and HOW-TO-RUN.md for the generated server pack.
-
zipBuilder
final Optional<File> zipBuilder(String minecraftVersion, String destination, String modloader, String modloaderVersion)
Create the ZIP-archive of the server pack, honoring the configured ZIP-exclusions.
-
preInstallationCleanup
final Unit preInstallationCleanup(String destination)
Delete configured leftover-files before a modloader-server installation.
-
getExplicitFiles
final List<ServerPackFile> getExplicitFiles(String source, String destination, String modpackDir, String serverPackDestination)
Gather all files for an explicit source-destination-combination.
-
getSaveFiles
final List<ServerPackFile> getSaveFiles(String clientDir, String directory, String destination)
Recursively gather all files of the given save-directory.
-
compileModList
final Pair<List<File>, List<File>> compileModList(PackConfig packConfig)
Generate the list of mods to include in the server pack from the given configuration.
-
compileModList
final Pair<List<File>, List<File>> compileModList(String modsDir, List<String> clientsideModsList, List<String> modWhitelist, String minecraftVersion, String modloader)
Generate the list of mods to include in the server pack, excluding clientside-only mods.
-
getDirectoryFiles
final List<ServerPackFile> getDirectoryFiles(String source, String destination)
Recursively gather all files of the given directory as source-destination-pairs.
-
excludeFileOrDirectory
final Boolean excludeFileOrDirectory(String modpackDir, File fileToCheckFor, List<Regex> exclusions)
Whether the given file or directory matches any of the given exclusion-regexes.
-
serverDownloadable
final Boolean serverDownloadable(String mcVersion, String modloader, String modloaderVersion)
Whether the installer for the given modloader-combination is available/reachable.
-
postInstallCleanup
final Unit postInstallCleanup(String destination)
Delete configured installer-leftovers after a modloader-server installation.
-
regexWalk
final Unit regexWalk(File source, String destination, Regex regex, List<ServerPackFile> serverPackFiles)
Gather every file matching the given regex from the source-directory.
-
-
-
-