Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
improv: Allow toggling of ServerStarterJar refresh, allow specifying version of SSJ to download

See merge request Griefed/ServerPackCreator!608

Closes #531
  • Loading branch information
Griefed committed Sep 11, 2024
2 parents 5fbde6c + ffe294f commit c656ad1
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,9 @@ private const val spcJabbaInstallVersionKey = "SPC_JABBA_INSTALL_VERSION_SPC"

private const val spcAdditionalArgsKey = "SPC_ADDITIONAL_ARGS_SPC"

private val scriptSettingsDefaultKeys = arrayOf(
spcVersionKey,
spcMinecraftVersionKey,
spcModloaderKey,
spcModloaderVersionKey,
spcJavaArgsKey,
spcFabricInstallerVersionKey,
spcQuiltInstallerVersionKey,
spcLegacyFabricInstallerVersionKey,
spcWaitForUserInputKey,
spcRestartServerKey,
spcSkipJavaCheckKey,
spcJDKVendorKey,
spcJabbaInstallURLShKey,
spcJabbaInstallURLPSKey,
spcJabbaInstallVersionKey,
spcAdditionalArgsKey
)
private const val spcServerStarterJarForceFetchKey = "SPC_SERVERSTARTERJAR_FORCE_FETCH_SPC"

private const val spcServerStarterJarVersionKey = "SPC_SERVERSTARTERJAR_VERSION_SPC"

/**
* A PackConfig contains the settings required to create a server pack.
Expand Down Expand Up @@ -574,7 +559,9 @@ open class PackConfig() {
Pair(spcJabbaInstallURLShKey,"https://github.com/Jabba-Team/jabba/raw/main/install.sh"),
Pair(spcJabbaInstallURLPSKey,"https://github.com/Jabba-Team/jabba/raw/main/install.ps1"),
Pair(spcJabbaInstallVersionKey,"0.13.0"),
Pair(spcAdditionalArgsKey,"-Dlog4j2.formatMsgNoLookups=true")
Pair(spcAdditionalArgsKey,"-Dlog4j2.formatMsgNoLookups=true"),
Pair(spcServerStarterJarForceFetchKey, "true"),
Pair(spcServerStarterJarVersionKey, "latest")
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,21 @@ class ServerPackHandler(
# - JAVA be set to 'java'
# - No 'java' command be available OR
# - The available Java version behind 'java' be incompatible with your Minecraft version.
# JABBA_VERSION has no effect on the installation of Jabba when using PowerShell.
# JABBA_INSTALL_VERSION has no effect on the installation of Jabba when using PowerShell.
# MINECRAFT_VERSION is tightly coupled with the modloader version. Be careful when changing this, as the new
# new version you set may not be compatible with the modloader and modloader version combination.
# MODLOADER and MODLOADER_VERSION same thing as with MINECRAFT_VERSION. Changing any of these three values may
# have unforseen consequences. Well, I say unforseen, it mostly causes the server to straight up not start,
# because of incompatibilities. Be very careful when changing these!
# SERVERSTARTERJAR_FORCE_FETCH true/false allows you to enable/disable the force-refreshing of the server.jar
# when using Forge or NeoForge as your modloader. Force-refreshing means the file is replaced with a freshly
# downloaded one every time you run the start scripts.
# SERVERSTARTERJAR_VERSION allows you to manually set the version of the server.jar downloaded by the scripts.
# If you want to always use the latest version, set this to exactly "latest". For a specific version, see
# https://github.com/neoforged/ServerStarterJar/releases and use the tags on the left as the version,
# e.g. 0.1.24 or 0.1.25. When setting a specific version, make sure the release you pick actually has a server.jar
# available for download. When the download fails with the "latest"-setting, then pick a specific one and/or
# contact the devs of the ServerStarterJar about the latest release not having a server.jar to download.
#
# DO NOT EDIT THE FOLLOWING VARIABLES MANUALLY
# - FABRIC_INSTALLER_VERSION
Expand Down Expand Up @@ -151,6 +160,8 @@ class ServerPackHandler(
JABBA_INSTALL_URL_SH=SPC_JABBA_INSTALL_URL_SH_SPC
JABBA_INSTALL_URL_PS=SPC_JABBA_INSTALL_URL_PS_SPC
JABBA_INSTALL_VERSION=SPC_JABBA_INSTALL_VERSION_SPC
SERVERSTARTERJAR_FORCE_FETCH=SPC_SERVERSTARTERJAR_FORCE_FETCH_SPC
SERVERSTARTERJAR_VERSION=SPC_SERVERSTARTERJAR_VERSION_SPC
""".trimIndent()
private val howToStartTheServer = """
# How To Start / Run The Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,36 @@ Function DownloadIfNotExists
#>
}

Function global:RefreshServerJar
{
if ("${ServerStarterJarForceFetch}" -eq "true")
{
DeleteFileSilently 'server.jar'
}

$ServerStarterJarDownloadURL = ""
if ("${ServerStarterJarVersion}" -eq "latest")
{
$ServerStarterJarDownloadURL = "https://github.com/neoforged/ServerStarterJar/releases/latest/download/server.jar"
}
else
{
$ServerStarterJarDownloadURL = "https://github.com/neoforged/ServerStarterJar/releases/download/${ServerStarterJarVersion}/server.jar"
}

DownloadIfNotExists "server.jar" "server.jar" "${ServerStarterJarDownloadURL}"

<#
.SYNOPSIS
Refresh the ServerStarterJar used for running Forge and NeoForge servers.
Depending on the value of SERVERSTARTERJAR_FORCE_FETCH in the variables.txt the server.jar is force-refreshed.
Meaning: If true, the server.jar will be deleted and then downloaded again.
Depending on the value of SERVERSTARTERJAR_VERSION in the variables.txt a different version is fetched. More on
this value in the variables.txt
#>
}

Function global:SetupForge
{
""
Expand Down Expand Up @@ -335,8 +365,7 @@ Function global:SetupForge

$script:ServerRunCommand = "@user_jvm_args.txt -Djava.security.manager=allow -jar server.jar --installer-force --installer ${ForgeInstallerUrl} nogui"

DeleteFileSilently 'server.jar'
DownloadIfNotExists "server.jar" "server.jar" "https://github.com/neoforged/ServerStarterJar/releases/latest/download/server.jar"
RefreshServerJar
}

<#
Expand Down Expand Up @@ -376,8 +405,7 @@ Function global:SetupNeoForge
$script:ServerRunCommand = "@user_jvm_args.txt -jar server.jar --installer-force --installer ${ModLoaderVersion} nogui"
}

DeleteFileSilently 'server.jar'
DownloadIfNotExists "server.jar" "server.jar" "https://github.com/neoforged/ServerStarterJar/releases/latest/download/server.jar"
RefreshServerJar

<#
.SYNOPSIS
Expand Down Expand Up @@ -574,6 +602,8 @@ $AdditionalArgs = $ExternalVariables['ADDITIONAL_ARGS']
$Restart = $ExternalVariables['RESTART']
$SkipJavaCheck = $ExternalVariables['SKIP_JAVA_CHECK']
$RecommendedJavaVersion = $ExternalVariables['RECOMMENDED_JAVA_VERSION']
$ServerStarterJarForceFetch = $ExternalVariables['SERVERSTARTERJAR_FORCE_FETCH']
$ServerStarterJarVersion = $ExternalVariables['SERVERSTARTERJAR_VERSION']
$LauncherJarLocation = "do_not_manually_edit"
$ServerRunCommand = "do_not_manually_edit"
$JavaVersion = "do_not_manually_edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,30 @@ downloadIfNotExist() {
# runJavaCommand(command)
# Runs the command $1 using the Java installation set in $JAVA.
runJavaCommand() {
# shellcheck disable=SC2086
"$JAVA" ${1}
}

# refreshServerJar
# Refresh the ServerStarterJar used for running Forge and NeoForge servers.
# Depending on the value of SERVERSTARTERJAR_FORCE_FETCH in the variables.txt the server.jar is force-refreshed.
# Meaning: If true, the server.jar will be deleted and then downloaded again.
# Depending on the value of SERVERSTARTERJAR_VERSION in the variables.txt a different version is fetched. More on
# this value in the variables.txt
refreshServerJar() {
if [[ "${SERVERSTARTERJAR_FORCE_FETCH}" == "true" ]]; then
rm -f server.jar
fi

if [[ "${SERVERSTARTERJAR_VERSION}" == "latest" ]]; then
SERVERSTARTERJAR_DOWNLOAD_URL="https://github.com/neoforged/ServerStarterJar/releases/latest/download/server.jar"
else
SERVERSTARTERJAR_DOWNLOAD_URL="https://github.com/neoforged/ServerStarterJar/releases/download/${SERVERSTARTERJAR_VERSION}/server.jar"
fi

downloadIfNotExist "server.jar" "server.jar" "${SERVERSTARTERJAR_DOWNLOAD_URL}"
}

# setupForge
# Download and install a Forge server for $MODLOADER_VERSION. For Minecraft 1.17 and newer the ServerStarterJar from the
# NeoForge-group is used. This has the benefit of making this server pack compatible with most hosting-companies.
Expand Down Expand Up @@ -196,8 +217,7 @@ setupForge() {

SERVER_RUN_COMMAND="@user_jvm_args.txt -Djava.security.manager=allow -jar server.jar --installer-force --installer ${FORGE_INSTALLER_URL} nogui"

rm -f server.jar
downloadIfNotExist "server.jar" "server.jar" "https://github.com/neoforged/ServerStarterJar/releases/latest/download/server.jar"
refreshServerJar
fi
}

Expand Down Expand Up @@ -229,8 +249,7 @@ setupNeoForge() {
SERVER_RUN_COMMAND="@user_jvm_args.txt -jar server.jar --installer-force --installer ${MODLOADER_VERSION} nogui"
fi

rm -f server.jar
downloadIfNotExist "server.jar" "server.jar" "https://github.com/neoforged/ServerStarterJar/releases/latest/download/server.jar"
refreshServerJar
}

# setupFabric
Expand Down

0 comments on commit c656ad1

Please sign in to comment.