Skip to content

Commit

Permalink
Merge branch 'template-table' into 'alpha'
Browse files Browse the repository at this point in the history
Various script related changes

See merge request Griefed/ServerPackCreator!586
  • Loading branch information
Griefed committed Jun 23, 2024
2 parents 5abcaac + 1ba5b35 commit 0ad2470
Show file tree
Hide file tree
Showing 23 changed files with 1,190 additions and 356 deletions.
162 changes: 107 additions & 55 deletions HELP.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ settings.global.aikars.label=Global Aikars Flags
settings.global.scripts.tooltip=Script templates used for creating the start scripts for generated server packs.
settings.global.scripts.label=Script Templates
settings.global.scripts.chooser=Script Template Chooser
settings.global.scripts.key=Type
settings.global.scripts.value=Path to script template
settings.global.scripts.missing=One or more templates does not exist!
settings.global.javascripts.tooltip=Script templates used for creating the Java install-scripts for generated server packs.
settings.global.javascripts.label=Java Script Templates
settings.global.javascripts.chooser=Java script Template Chooser
settings.global.javascripts.key=Type
settings.global.javascripts.value=Path to sava script template
settings.global.javascripts.missing=One or more templates does not exist!
settings.global.fallbackurl.tooltip=URL to .properties-file containing default clientside-mods-list.
settings.global.fallbackurl.label=Properties URL
settings.global.exclusions.tooltip=Exclusion-method to use for clientside-mods exclusions
Expand Down Expand Up @@ -655,4 +664,5 @@ migrationmanager.migration.fourpointzeropointzero.addons=Migrated addons-directo
migrationmanager.migration.fourpointzeropointzero.addons.disabled=Disabled plugin {0} to prevent crashes due to probable version incompatibility.
migrationmanager.migration.fourpointzeropointzero.locale=Migrated locale setting from {0} to en_GB.
migrationmanager.migration.fivepointzeropointzero.scripts.default=Migrated default script-template(s) setting to new specs.
migrationmanager.migration.fivepointzeropointzero.scripts.custom=Migrated custom script-template(s) setting to new specs.
migrationmanager.migration.fivepointzeropointzero.scripts.custom=Migrated custom script-template(s) setting to new specs.
migrationmanager.migration.sixpointzeropointzero.scripts.template=Migrated custom script-template to new setting: {0}.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ class ApiProperties(
"de.griefed.serverpackcreator.serverpack.zip.exclude"
private val pServerPackZipExclusionEnabled =
"de.griefed.serverpackcreator.serverpack.zip.exclude.enabled"
@Deprecated("Deprecated as of 6.0.0")
private val pServerPackScriptTemplates =
"de.griefed.serverpackcreator.serverpack.script.template"
private val pServerPackStartScriptTemplatesPrefix =
"de.griefed.serverpackcreator.serverpack.script.template."
private val pServerPackJavaScriptTemplatesPrefix =
"de.griefed.serverpackcreator.serverpack.java.template."
private val pPostInstallCleanupFiles =
"de.griefed.serverpackcreator.install.post.files"
private val pPreInstallCleanupFiles =
Expand Down Expand Up @@ -927,6 +932,7 @@ class ApiProperties(
*
* @author Griefed
*/
@Deprecated("Deprecated as of 6.0.0", ReplaceWith("defaultScriptTemplateMap"))
fun defaultScriptTemplates(): List<File> {
// See whether we have custom files.
val currentFiles = serverFilesDirectory.walk().maxDepth(1).filter {
Expand Down Expand Up @@ -978,10 +984,7 @@ class ApiProperties(
return newTemplates.toList()
}

/**
* Start-script templates to use during server pack generation.
*/
@Suppress("SetterBackingFieldAssignment")
@Deprecated("Deprecated as of 6.0.0",ReplaceWith("startScriptTemplates"))
var scriptTemplates: TreeSet<File> = TreeSet<File>()
get() {
val scriptSetting = internalProps.getProperty(pServerPackScriptTemplates)
Expand All @@ -1008,6 +1011,94 @@ class ApiProperties(
}
}

/**
* Default map of start-script templates: sh, ps1, bat.
*/
fun defaultStartScriptTemplates() : HashMap<String, String> {
return hashMapOf(
Pair("sh", File(serverFilesDirectory.absolutePath, defaultShellScriptTemplate.name).absolutePath),
Pair("ps1", File(serverFilesDirectory.absolutePath, defaultPowerShellScriptTemplate.name).absolutePath),
Pair("bat", File(serverFilesDirectory.absolutePath, defaultBatchScriptTemplate.name).absolutePath)
)
}

/**
* Start-script templates to use during server pack generation.
* Each key represents a different template and script-type.
*/
var startScriptTemplates: HashMap<String,String> = hashMapOf()
get() {
val templateProps = internalProps.keys
.filter { entry -> (entry as String).startsWith(pServerPackStartScriptTemplatesPrefix) }
.map { entry -> entry as String }
var type: String
if (templateProps.isEmpty() || templateProps.any { entry -> entry.replace(pServerPackStartScriptTemplatesPrefix,"").isBlank() }) {
log.error("Found empty definitions for start script templates. Using defaults.")
field = defaultStartScriptTemplates()
} else {
for (templateProp in templateProps) {
type = templateProp.replace(pServerPackStartScriptTemplatesPrefix,"")
field[type] = File(internalProps[templateProp] as String).absolutePath
}
}
if (field.isEmpty()) {
log.error("No start script templates defined. Using defaults.")
field = defaultStartScriptTemplates()
}
return field
}
set(map) {
for ((key, value) in map) {
defineProperty("$pServerPackStartScriptTemplatesPrefix$key", value)
log.info("Set $pServerPackStartScriptTemplatesPrefix$key to $value")
}
field = map
}

/**
* Default map of start-script templates: sh, ps1, bat.
*/
fun defaultJavaScriptTemplates() : HashMap<String, String> {
return hashMapOf(
Pair("sh", File(serverFilesDirectory.absolutePath, defaultJavaShellScriptTemplate.name).absolutePath),
Pair("ps1", File(serverFilesDirectory.absolutePath, defaultJavaPowerShellScriptTemplate.name).absolutePath),
Pair("bat", File(serverFilesDirectory.absolutePath, defaultJavaBatchScriptTemplate.name).absolutePath)
)
}

/**
* Start-script templates to use during server pack generation.
* Each key represents a different template and script-type.
*/
var javaScriptTemplates: HashMap<String,String> = hashMapOf()
get() {
val templateProps = internalProps.keys
.filter { entry -> (entry as String).startsWith(pServerPackJavaScriptTemplatesPrefix) }
.map { entry -> entry as String }
var type: String
if (templateProps.isEmpty() || templateProps.any { entry -> entry.replace(pServerPackJavaScriptTemplatesPrefix,"").isBlank() }) {
log.error("Found empty definitions for java script templates. Using defaults.")
field = defaultStartScriptTemplates()
} else {
for (templateProp in templateProps) {
type = templateProp.replace(pServerPackJavaScriptTemplatesPrefix,"")
field[type] = File(internalProps[templateProp] as String).absolutePath
}
}
if (field.isEmpty()) {
log.error("No java script templates defined. Using defaults.")
field = defaultStartScriptTemplates()
}
return field
}
set(map) {
for ((key, value) in map) {
defineProperty("$pServerPackJavaScriptTemplatesPrefix$key", value)
log.info("Set $pServerPackJavaScriptTemplatesPrefix$key to $value")
}
field = map
}

/**
* The URL from which a .properties-file is read during updating of the fallback clientside-mods list.
* The default can be found in [fallbackUpdateURL].
Expand Down Expand Up @@ -1824,28 +1915,49 @@ class ApiProperties(
* The default shell-template for the modded server start scripts. The file returned by this
* method does not represent the script-template in the `server_files`-directory. If you
* wish access the configured script templates inside the `server_files`-directory, use
* [scriptTemplates].
* [startScriptTemplates].
*/
val defaultShellScriptTemplate = File(serverFilesDirectory, "default_template.sh")

/**
* The default PowerShell-template for the modded server start scripts. The file returned by this
* method does not represent the script-template in the `server_files`-directory. If you
* wish access the configured script templates inside the `server_files`-directory, use
* [scriptTemplates].
* [startScriptTemplates].
*/
val defaultPowerShellScriptTemplate = File(serverFilesDirectory, "default_template.ps1")

/**
* The default Batch-template for the modded server start scripts. The file returned by this
* method does not represent the script-template in the `server_files`-directory. If you
* wish access the configured script templates inside the `server_files`-directory, use
* [scriptTemplates].
* [startScriptTemplates].
*/
val defaultBatchScriptTemplate = File(serverFilesDirectory, "default_template.bat")

@Suppress("MemberVisibilityCanBePrivate")
val fallbackScriptTemplates = defaultScriptTemplates().joinToString(",")
/**
* The default shell-template for the modded server start scripts. The file returned by this
* method does not represent the script-template in the `server_files`-directory. If you
* wish access the configured script templates inside the `server_files`-directory, use
* [javaScriptTemplates].
*/
val defaultJavaShellScriptTemplate = File(serverFilesDirectory, "default_java_template.sh")

/**
* The default PowerShell-template for the modded server start scripts. The file returned by this
* method does not represent the script-template in the `server_files`-directory. If you
* wish access the configured script templates inside the `server_files`-directory, use
* [javaScriptTemplates].
*/
val defaultJavaPowerShellScriptTemplate = File(serverFilesDirectory, "default_java_template.ps1")

/**
* The default Batch-template for the modded server start scripts. The file returned by this
* method does not represent the script-template in the `server_files`-directory. If you
* wish access the configured script templates inside the `server_files`-directory, use
* [javaScriptTemplates].
*/
val defaultJavaBatchScriptTemplate = File(serverFilesDirectory, "default_java_template.bat")

/**
* Directory in which the properties for quick selection are to be stored in and retrieved from.
Expand Down Expand Up @@ -2563,8 +2675,8 @@ class ApiProperties(
log.info(" Java $key path: $value")
}
log.info("Using script templates:")
for (template in scriptTemplates) {
log.info(" " + template.path)
for ((key, value) in startScriptTemplates) {
log.info(" $key: $value")
}
log.info("============================== PROPERTIES ==============================")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ class ApiWrapper private constructor(

System.setProperty("file.encoding", StandardCharsets.UTF_8.name())
if (!utilities.fileUtilities.isReadWritePermissionSet(apiProperties.getJarFolder())) {
log.error(
"One or more file or directory has no read- or write-permission." + " This may lead to corrupted server packs!" + " Check the permissions of the ServerPackCreator base directory!"
)
log.error("One or more file or directory has no read- or write-permission. " +
"This may lead to corrupted server packs! " +
"Check the permissions of the ServerPackCreator base directory!")
}

try {
Expand Down Expand Up @@ -503,6 +503,9 @@ class ApiWrapper private constructor(
overwriteServerFilesFile(apiProperties.defaultShellScriptTemplate)
overwriteServerFilesFile(apiProperties.defaultPowerShellScriptTemplate)
overwriteServerFilesFile(apiProperties.defaultBatchScriptTemplate)
overwriteServerFilesFile(apiProperties.defaultJavaShellScriptTemplate)
overwriteServerFilesFile(apiProperties.defaultJavaPowerShellScriptTemplate)
overwriteServerFilesFile(apiProperties.defaultJavaBatchScriptTemplate)
if (serverProperties || serverIcon) {
log.warn("#################################################################")
log.warn("#.............ONE OR MORE DEFAULT FILE(S) GENERATED.............#")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,30 +606,64 @@ class ConfigurationHandler(
*/
fun ensureScriptSettingsDefaults(packConfig: PackConfig) {
val server = versionMeta.minecraft.getServer(packConfig.minecraftVersion)
if (!server.isPresent || !server.get().url().isPresent) {
packConfig.scriptSettings["SPC_MINECRAFT_SERVER_URL_SPC"] = ""
} else {
packConfig.scriptSettings["SPC_MINECRAFT_SERVER_URL_SPC"] = server.get().url().get().toString()
}

//From modpack -> server pack specific values
packConfig.scriptSettings["SPC_SERVERPACKCREATOR_VERSION_SPC"] = apiProperties.apiVersion
packConfig.scriptSettings["SPC_MINECRAFT_VERSION_SPC"] = packConfig.minecraftVersion
packConfig.scriptSettings["SPC_MODLOADER_SPC"] = packConfig.modloader
packConfig.scriptSettings["SPC_MODLOADER_VERSION_SPC"] = packConfig.modloaderVersion
packConfig.scriptSettings["SPC_JAVA_ARGS_SPC"] = packConfig.javaArgs
if (!packConfig.scriptSettings.containsKey("SPC_JAVA_SPC")) {
packConfig.scriptSettings["SPC_JAVA_SPC"] = "java"
}
packConfig.scriptSettings["SPC_FABRIC_INSTALLER_VERSION_SPC"] = versionMeta.fabric.releaseInstaller()
packConfig.scriptSettings["SPC_QUILT_INSTALLER_VERSION_SPC"] = versionMeta.quilt.releaseInstaller()
packConfig.scriptSettings["SPC_LEGACYFABRIC_INSTALLER_VERSION_SPC"] =
versionMeta.legacyFabric.releaseInstaller()
packConfig.scriptSettings["SPC_LEGACYFABRIC_INSTALLER_VERSION_SPC"] = versionMeta.legacyFabric.releaseInstaller()

if (server.isEmpty || server.get().url().isEmpty) {
packConfig.scriptSettings["SPC_MINECRAFT_SERVER_URL_SPC"] = ""
packConfig.scriptSettings["SPC_RECOMMENDED_JAVA_VERSION_SPC"] = ""
} else {
packConfig.scriptSettings["SPC_MINECRAFT_SERVER_URL_SPC"] = server.get().url().get().toString()
if (server.get().javaVersion().isPresent) {
packConfig.scriptSettings["SPC_RECOMMENDED_JAVA_VERSION_SPC"] = server.get().javaVersion().get().toString()
} else {
packConfig.scriptSettings["SPC_RECOMMENDED_JAVA_VERSION_SPC"] = "?"
}
}

val neoForgeInstance = versionMeta.neoForge.getNeoForgeInstance(packConfig.minecraftVersion, packConfig.modloaderVersion)
packConfig.scriptSettings["SPC_NEOFORGE_INSTALLER_URL_SPC"] = if (neoForgeInstance.isPresent) {
versionMeta.neoForge.getNeoForgeInstance(packConfig.minecraftVersion, packConfig.modloaderVersion).get().installerUrl.toString()
neoForgeInstance.get().installerUrl.toString()
} else {
"NONE"
}

// Additional, fluff
if (!packConfig.scriptSettings.containsKey("SPC_RESTART_SPC")) {
packConfig.scriptSettings["SPC_RESTART_SPC"] = "false"
}
if (!packConfig.scriptSettings.containsKey("SPC_SKIP_JAVA_CHECK_SPC")) {
packConfig.scriptSettings["SPC_SKIP_JAVA_CHECK_SPC"] = "false"
}
if (!packConfig.scriptSettings.containsKey("SPC_JDK_VENDOR_SPC")) {
packConfig.scriptSettings["SPC_JDK_VENDOR_SPC"] = "temurin"
}
if (!packConfig.scriptSettings.containsKey("SPC_JABBA_INSTALL_URL_SH_SPC")) {
packConfig.scriptSettings["SPC_JABBA_INSTALL_URL_SPC"] = "https://github.com/Jabba-Team/jabba/raw/main/install.sh"
}
if (!packConfig.scriptSettings.containsKey("SPC_JABBA_INSTALL_URL_PS_SPC")) {
packConfig.scriptSettings["SPC_JABBA_INSTALL_URL_SPC"] = "https://github.com/Jabba-Team/jabba/raw/main/install.ps1"
}
if (!packConfig.scriptSettings.containsKey("SPC_JABBA_INSTALL_VERSION_SPC")) {
packConfig.scriptSettings["SPC_JABBA_INSTALL_VERSION_SPC"] = "0.13.0"
}
if (!packConfig.scriptSettings.containsKey("SPC_ADDITIONAL_ARGS_SPC")) {
packConfig.scriptSettings["SPC_ADDITIONAL_ARGS_SPC"] = "-Dlog4j2.formatMsgNoLookups=true"
}
if (!packConfig.scriptSettings.containsKey("SPC_JAVA_SPC")) {
packConfig.scriptSettings["SPC_JAVA_SPC"] = "java"
}
if (!packConfig.scriptSettings.containsKey("SPC_WAIT_FOR_USER_INPUT_SPC")) {
packConfig.scriptSettings["SPC_WAIT_FOR_USER_INPUT_SPC"] = "true"
}
}

/**
Expand Down
Loading

0 comments on commit 0ad2470

Please sign in to comment.