Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# VARIABLE DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- $currentLocation= Split-Path -parent $PSCommandPath
- $configPath = $currentLocation+'\config.xml'
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# POWERSHELL CUSTOMIZATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- $consoleName="Console Master"
- $consoleVersion='1.0'
- $prefix="$consoleName $consoleVersion"
- $ui = (Get-Host).UI.RawUI
- $ui.WindowTitle = "$prefix"
- function Create-Config([string]$jarFile, [string]$minecraftVersion){
- $settings = [PSCustomObject]@{
- server_jar=$jarFile;
- server_version=$minecraftVersion
- server_location=$currentLocation
- jar_flags='-Xms1G -Xmx1G';
- jar_options='-o true'
- }
- Export-Clixml -Path $configPath -InputObject $settings
- }
- function Setup-Prompt {
- $ui.WindowTitle = "$prefix+: First-Time Setup"
- Menu
- Write-Host Welcome to $prefix!
- Write-Host ""
- Write-Host Let me get to know about your server better
- Write-Host ""
- $jarFile = Read-Host –Prompt "Enter your server's .jar file w/o the extension"
- $minecraftVersion = Read-Host -Prompt "Enter your server's Minecraft version"
- Create-Config($jarFile, $minecraftVersion)
- Write-Host Basic Setup Complete!
- Write-Host Moving to main menu..
- #Main-Menu
- }
- function Main-Menu (){
- $settings = Import-Clixml -Path $configPath
- $ui.WindowTitle = "$prefix+: Main Menu"
- Clear-Host
- Write-Host "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# Main Menu #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
- Write-Host "1. Start The Server"
- Write-Host "2. Settings"
- Write-Host "3. Exit"
- $mainMenuInput = Read-Host "Please make a selection: "
- if(mainMenuInput != ){
- Write-Host "Invalid Choice!"
- }
- }
- function Start-Server(){
- $consoleServerPrefix = "[+$consoleName+]:"
- $ui.WindowTitle = "$prefix+: Server Running (Jar: $settings.server_jar, MC $settings.minecraftVersion)"
- Clear-Host
- Write-Host "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# Main Menu #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
- Write-Host "$consoleServerPrefix Server Starting!"
- #-#-#-#-# Ngrok Checking here #-#-#-#-#
- Write-Host "$consoleServerPrefix Checking for Ngrok process..."
- #Already Started
- Write-Host "$consoleServerPrefix Ngrok is Already Running! Skipping Ngrok Startup..."
- #Not Started
- Write-Host "$consoleServerPrefix Ngrok Not Running! Starting Ngrok..."
- start powershell {ngrok tcp 25565}
- Write-Host "$consoleServerPrefix Ngrok Started!"
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- Write-Host "$consoleServerPrefix Loading Java Arguments..."
- $settings = Import-Clixml -Path $configPath
- $server = $currentLocation+'\forge.jar'
- java -Xms1G -Xmx1G -jar C:\Users\novag\Documents\Powershell\forge.jar -o true
- Write-Host "Server is ending"
- }
- function Change-Minecraft-Version(){
- }
- function Change-RAM(){
- }
- function Change-Arguments(){
- }
- function Factory-Reset(){
- }
- function Settings-Menu(){
- $ui.WindowTitle = "$prefix+: Settings Menu"
- Clear-Host
- Write-Host "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# Settings Menu #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
- Write-Host "1. Change Minecraft Version - Change What Version of Minecraft the Server is Using"
- Write-Host "2. RAM Allocation - Set RAM Allocation (Advanced)"
- Write-Host "3. Custom Arguments - Set custom arguments besides the RAM! (Advanced)"
- Write-Host "4. Factory Reset [!!]"
- Write-Host "5. Back To Main Menu"
- }
- #Function to quit the auto relaunch based on a time set.
- Function Set-Quit([int]$delay) {
- Write-Host ""
- Write-Host -background Red "Press q to quit - you have $delay seconds to decide"
- Start-Sleep -s $delay
- If ($ui.KeyAvailable -and ("q" -eq $ui.ReadKey("IncludeKeyUp,NoEcho").Character)) {
- Write-Host -foreground Red "Exiting Script..."
- Return $true;
- }
- Return $false
- }
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# BEGIN FUNCTION CALLS #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- #Main area of the script. This launches all functions above (PowerShell needs the functions declared before they can be ran).
- #Keep looping until the user quits the script.
- Do {
- Clear-Host
- #Import Variables
- If (!(Test-Path $configPath)) {
- Setup-Prompt
- }
- Main-Menu
- switch($mainMenuInput){
- '1' {
- cls
- Start-Server
- }
- '2' {
- cls
- Settings-Menu
- }
- '3' {
- cls
- break;
- }
- }
- } Until (Set-Quit (5))
- Write-Host "Press any key to exit"
- $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") > $NULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement