Created
February 20, 2023 19:54
-
-
Save mja00/acaeee3da6eeb39d3df28571dd740f56 to your computer and use it in GitHub Desktop.
This will install a Paper server with the ServerTap plugin into a folder of your choosing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################### | |
# Author: mja00 | |
# Version: 1.0 | |
# Date: 2023-02-20 | |
# Description: TikTok Tikfinity Server Installer | |
#################################################### | |
# Check if winget is installed | |
$winget = Get-Command winget -ErrorAction SilentlyContinue | |
if ($winget -eq $null) { | |
Write-Host "winget is not installed. Please install winget and re-run this script." | |
# Open the Store site to install winget | |
Start-Process -FilePath "https://www.microsoft.com/store/productId/9NBLGGH5NNS1" | |
exit | |
} | |
# Check if Java is currently installed | |
$java = Get-Command java -ErrorAction SilentlyContinue | |
# If Java is not installed, install it | |
if ($java -eq $null) { | |
Write-Host "Java is not installed. Installing Java..." | |
winget install -e --id Amazon.Corretto.17 | |
} else { | |
# Check the version of Java installed | |
$javaVersion = java -version 2>&1 | findstr "version" | |
# Strip out the version number | |
$javaVersion = $javaVersion -replace ".*""(.*)\..*"".*", '$1' | |
Write-Host "Java is installed. Version: $javaVersion" | |
# Check if the version is 17 or higher | |
# Get the value before the first . | |
$majorVersion = $javaVersion -replace "([0-9]+)\..*", '$1' | |
if ($majorVersion -lt 17) { | |
Write-Host "Java version is not 17 or higher. Please uninstall Java and re-run this script." | |
} | |
} | |
# Paper install | |
# Check if paper.jar already exists | |
if (Test-Path -Path "paper.jar") { | |
Write-Host "Paper already exists. Skipping download..." | |
} else { | |
Write-Host "Downloading Paper..." | |
# Make a request to the Paper API | |
$paper = Invoke-WebRequest -Uri "https://api.papermc.io/v2/projects/paper" -UseBasicParsing | |
# Parse the json response | |
$paper = $paper.Content | ConvertFrom-Json | |
# Get the last item in the versions array | |
$minecraftVersion = $paper.versions[-1] | |
# Get the latest build number | |
$paper2 = Invoke-WebRequest -Uri "https://api.papermc.io/v2/projects/paper/versions/$minecraftVersion" -UseBasicParsing | |
$paper2 = $paper2.Content | ConvertFrom-Json | |
$buildNumber = $paper2.builds[-1] | |
# Download the latest build | |
Invoke-WebRequest -Uri "https://papermc.io/api/v2/projects/paper/versions/$minecraftVersion/builds/$buildNumber/downloads/paper-$minecraftVersion-$buildNumber.jar" -OutFile paper.jar | |
} | |
# Write to eula.txt | |
Set-Content -Path "eula.txt" -Value "eula=true" | |
if (-Not (Test-Path -Path "plugins")) { | |
# Make the directory | |
New-Item -ItemType Directory -Path "plugins" | |
New-Item -ItemType Directory -Path "plugins\update" | |
} | |
# Download ServerTap | |
# Get the releases from Github | |
$releases = Invoke-WebRequest -Uri "https://api.github.com/repos/phybros/servertap/releases/latest" -UseBasicParsing | |
# Parse the json response | |
$releases = $releases.Content | ConvertFrom-Json | |
# Loop through the assets and find one with .jar in the name | |
foreach ($asset in $releases.assets) { | |
if ($asset.name -like "*.jar") { | |
$name = $asset.name | |
# Check if this file already exists | |
if (Test-Path -Path "plugins\$name") { | |
Write-Host "$name already exists. Skipping download..." | |
} else { | |
# Delete any existing ServerTap files | |
Get-ChildItem -Path "plugins" -Filter "ServerTap*.jar" | Remove-Item | |
Write-Host "Downloading $name..." | |
$url = $asset.browser_download_url | |
Invoke-WebRequest -Uri $url -OutFile "plugins\$name" | |
} | |
} | |
} | |
# Create a run.bat file | |
Set-Content -Path "run.bat" -Value "java -Xms4096M -Xmx4096M --add-modules=jdk.incubator.vector -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -jar paper.jar --nogui" | |
# Start the server | |
Write-Host "Starting server..." | |
# Set fore color to red | |
Write-Host "#################################################" -ForegroundColor Red | |
Write-Host "#################################################" -ForegroundColor Red | |
Write-Host "DO NOT CLOSE THIS WINDOW OR THE SERVER WILL STOP!" -ForegroundColor Red | |
Write-Host "DO NOT CLOSE THIS WINDOW OR THE SERVER WILL STOP!" -ForegroundColor Red | |
Write-Host "DO NOT CLOSE THIS WINDOW OR THE SERVER WILL STOP!" -ForegroundColor Red | |
Write-Host "#################################################" -ForegroundColor Red | |
Write-Host "#################################################" -ForegroundColor Red | |
# Start the server | |
.\run.bat | |
# Server has stopped, print out some info | |
Write-Host "#################################################" -ForegroundColor Green | |
Write-Host "If you want to start the server again, run run.bat" -ForegroundColor Green | |
Write-Host "If you want to update ServerTap, re-run this script" -ForegroundColor Green | |
Write-Host "If you want to update Paper, remove paper.jar and re-run this script" -ForegroundColor Green | |
Write-Host "#################################################" -ForegroundColor Green | |
# Don't let the window close | |
Read-Host -Prompt "Press Enter to exit..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment