Skip to content

Instantly share code, notes, and snippets.

@nfisherman
Last active March 8, 2023 07:32
Show Gist options
  • Select an option

  • Save nfisherman/7e87b269f8fe2d973bbcd9b9912f90ce to your computer and use it in GitHub Desktop.

Select an option

Save nfisherman/7e87b269f8fe2d973bbcd9b9912f90ce to your computer and use it in GitHub Desktop.
Powershell script to start up BungeeCord servers
# BungeeCord Multi-Server Starter - 03/08/2023
# © 2023 WTFPL
#################
### Variables ###
#################
# The name of the script that starts the server
[string]$START = "start.ps1"
# The default name of each jar file.
# First BungeeCord, then in the order declared.
# If no value set for a server, default is the last value.
[string[]]$JARS = "BungeeCord.jar", "server.jar"
# The name of the BungeeCord and server folders.
# First BungeeCord, then in the order declared.
# Seperated by commas.
[string[]]$NAMES = "BungeeCord","lobby"
# If you want the server GUI to appear.
# False leads to greater performance.
[string]$GUI = "false"
# The Xmx value for the servers to use.
# First BungeeCord, then in the order declared.
# If no value set for a server, default is the last value.
# Seperated by commas.
[int[]]$XMX = 512,1024
# The Xms value for the servers to use, in the order declared.
# First BungeeCord, then in the order declared.
# If no value set for a server, default is the last value.
# Seperated by commas.
[int[]]$XMS = 512
# If the Xms values should be the same as the Xmx values.
[string]$COPY_XMX = "true"
#######################
### The Actual Code ###
#######################
# Tidying up input
# Checks to see if it says ".jar" at the end and puts it there
# if it's not
for ($i = 0; $i -lt $JARS.length; $i++) {
$JAR = $JARS[$i]
$JAR = [string[]]$JAR[($JAR.length - 4)..($JAR.length)]
if (-join($JAR) -ne ".jar"){
$JARS[$i] = $JARS[$i] + ".jar"
}
}
if ([bool]::Parse($COPY_XMX)) { $XMS = $XMX }
if (-not ([bool]::Parse($GUI))){
$GUI = " -nogui"
} else {
$GUI = ""
}
$DIR = $PWD.ProviderPath
for ($i = 0; $i -lt $NAMES.length; $i++){
$NAME = $NAMES[$i]
$literallyJustForBungee = $GUI
if ($i -eq 0){
$literallyJustForBungee = ""
}
# Use the last Xms value for the rest of the servers if
# more servers than values
$bufferXMX = ""
if ($i -gt $XMX.length){
$bufferXMX = $XMX[$XMX.length - 1]
} else {
$bufferXMX = $XMX[$i]
}
# ^ Same thing but for Xmx
$bufferXMS = ""
if ($i -gt $XMS.length){
$bufferXMS = $XMS[$XMS.length - 1]
} else {
$bufferXMS = $XMS[$i]
}
# ^ Same thing but for jar file
$bufferJar = ""
if ($i -gt $JARS.length){
$bufferJar = $JARS[$JARS.length - 1]
} else {
$bufferJar = $JARS[$i]
}
# Configuring the command to start the server
$second = "java -jar -Xmx$($bufferXMX)M -Xms$($bufferXMS)M $($bufferJar)$literallyJustForBungee"
if (Test-Path -Path (Join-Path -Path $NAME -ChildPath $START) -PathType Leaf){
$second = ".\" + $START
}
# IDEK if you even need to correct for Windows vs Unix file paths
# in powershell
# I hate Microsoft
$dirConcat = Join-Path -Path $DIR -ChildPath $NAME
#Start another powershell instance with the server
Start-Process powershell.exe "-noexit -c Set-Location -LiteralPath `"$dirConcat`"; $second; exit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment