Skip to content

Commit

Permalink
improv: Refresh user_jvm_args.txt on launch. Improve readibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Jul 15, 2023
1 parent 280522d commit 46de35d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if ( (New-Object Security.Principal.WindowsPrincipal([Security.Principal.Windows
Write-Host "Warning! Running with administrator-privileges is not recommended."
}

Write-Host "Start script generated by ServerPackCreator SPC_SERVERPACKCREATOR_VERSION_SPC."
Write-Host "To change the launch settings of this server, such as JVM args / flags, Minecraft version, modloader version etc., edit the variables.txt-file."

# Acquire variable hashtable from variables.txt
$ExternalVariablesFile = Split-Path $script:MyInvocation.MyCommand.Path
$ExternalVariablesFile += "\variables.txt"
Expand Down Expand Up @@ -149,22 +152,21 @@ Function global:SetupForge
$script:MinecraftServerJarLocation = "libraries/net/minecraft/server/${MinecraftVersion}/server-${MinecraftVersion}.jar"
$script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true @user_jvm_args.txt @libraries/net/minecraftforge/forge/${MinecraftVersion}-${ModLoaderVersion}/win_args.txt nogui"

if (!(Test-Path -Path 'user_jvm_args.txt' -PathType Leaf))
{
"# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" +
"# They can take any number, followed by an M or a G.`n" +
"# M means Megabyte, G means Gigabyte.`n" +
"# For example, to set the maximum to 3GB: -Xmx3G`n" +
"# To set the minimum to 2.5GB: -Xms2500M`n" +
"# A good default for a modded server is 4GB.`n" +
"# Uncomment the next line to set it.`n" +
"# -Xmx4G`n" +
"${script:JavaArgs}" | Out-File user_jvm_args.txt -encoding utf8
}
else
{
"user_jvm_args.txt present..."
}
Write-Host "Generating user_jvm_args.txt from variables..."
Write-Host "Edit JAVA_ARGS in your variables.txt. Do not edit user_jvm_args.txt directly!"
Write-Host "Manually made changes to user_jvm_args.txt will be lost in the nether!"

DeleteFileSilently 'user_jvm_args.txt'

"# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" +
"# They can take any number, followed by an M or a G.`n" +
"# M means Megabyte, G means Gigabyte.`n" +
"# For example, to set the maximum to 3GB: -Xmx3G`n" +
"# To set the minimum to 2.5GB: -Xms2500M`n" +
"# A good default for a modded server is 4GB.`n" +
"# Uncomment the next line to set it.`n" +
"# -Xmx4G`n" +
"${script:JavaArgs}" | Out-File user_jvm_args.txt -encoding utf8
}

if ((DownloadIfNotExists "${ForgeJarLocation}" "forge-installer.jar" "${ForgeInstallerUrl}"))
Expand Down Expand Up @@ -196,7 +198,6 @@ Function global:SetupForge
Crash
}
}
""
}

# If modloader = Fabric, run Fabric-specific checks
Expand Down Expand Up @@ -259,13 +260,11 @@ Function global:SetupFabric
}
else
{
"fabric-server-launch.jar present. Moving on..."
$script:LauncherJarLocation = "fabric-server-launcher.jar"
$script:MinecraftServerJarLocation = "server.jar"
}
}
$script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true ${script:JavaArgs} -jar ${script:LauncherJarLocation} nogui"
""
}

# If modloader = Quilt, run Quilt-specific checks
Expand Down Expand Up @@ -300,14 +299,10 @@ Function global:SetupQuilt
}

}
else
{
"quilt-server-launch.jar present. Moving on..."
}

$script:LauncherJarLocation = "quilt-server-launch.jar"
$script:MinecraftServerJarLocation = "server.jar"
$script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true ${JavaArgs} -jar ${LauncherJarLocation} nogui"
""
}

# If modloader = LegacyFabric, run LegacyFabric-specific checks
Expand Down Expand Up @@ -342,20 +337,15 @@ Function global:SetupLegacyFabric
}

}
else
{
"fabric-server-launch.jar present. Moving on..."
}

$script:LauncherJarLocation = "fabric-server-launch.jar"
$script:MinecraftServerJarLocation = "server.jar"
$script:ServerRunCommand = "-Dlog4j2.formatMsgNoLookups=true ${JavaArgs} -jar ${LauncherJarLocation} nogui"
""
}

# Check for a minecraft server and download it if necessary
Function global:Minecraft
{
""
if (($ModLoader -eq "Fabric") -and (${ImprovedFabricLauncherAvailable} -eq "200"))
{
"Skipping Minecraft Server JAR checks because we are using the improved Fabric Server Launcher."
Expand All @@ -364,13 +354,11 @@ Function global:Minecraft
{
(DownloadIfNotExists "${MinecraftServerJarLocation}" "${MinecraftServerJarLocation}" "${MinecraftServerUrl}") > $null
}
""
}

# Check for eula.txt and generate if necessary
Function Eula
{
""
if (!(Test-Path -Path 'eula.txt' -PathType Leaf))
{
"Mojang's EULA has not yet been accepted. In order to run a Minecraft server, you must accept Mojang's EULA."
Expand All @@ -381,7 +369,6 @@ Function Eula
if (${Answer} -eq "I agree")
{
"User agreed to Mojang's EULA."

"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).`n" +
"eula=true" | Out-File eula.txt -encoding utf8
}
Expand All @@ -393,21 +380,14 @@ Function Eula
Crash
}
}
else
{
"eula.txt present. Moving on..."
}
""
}

if ( ${PSScriptRoot}.Contains(" "))
{
"WARNING! The current location of this script contains spaces. This may cause this server to crash!"
"It is strongly recommended to move this server pack to a location whose path does NOT contain SPACES!"
""
"Current path:"
"${PSScriptRoot}"
""

$WhyMustPowerShellBeThisWayLikeSeriouslyWhatTheFrag = Read-Host -Prompt 'Are you sure you want to continue? (Yes/No): '

Expand Down Expand Up @@ -453,7 +433,6 @@ Eula

""
"Starting server..."
""
"Minecraft version: ${MinecraftVersion}"
"Modloader: ${ModLoader}"
"Modloader version: ${ModLoaderVersion}"
Expand Down
Loading

0 comments on commit 46de35d

Please sign in to comment.