Advertisement
NovaViper

Untitled

Jun 1st, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# VARIABLE DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  2. $currentLocation= Split-Path -parent $PSCommandPath
  3. $configPath = $currentLocation+'\config.xml'
  4.  
  5. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# POWERSHELL CUSTOMIZATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  6. $consoleName="Console Master"
  7. $consoleVersion='1.0'
  8. $prefix="$consoleName $consoleVersion"
  9.  
  10. $ui = (Get-Host).UI.RawUI
  11. $ui.WindowTitle = "$prefix"
  12.  
  13. function Create-Config([string]$jarFile, [string]$minecraftVersion){
  14.  
  15.     $settings = [PSCustomObject]@{
  16.         server_jar=$jarFile;
  17.         server_version=$minecraftVersion
  18.         server_location=$currentLocation
  19.         jar_flags='-Xms1G -Xmx1G';
  20.         jar_options='-o true'
  21.     }
  22.  
  23.     Export-Clixml -Path $configPath -InputObject $settings
  24. }
  25.  
  26.  
  27. function Setup-Prompt {
  28.     $ui.WindowTitle = "$prefix+: First-Time Setup"
  29.  
  30.     Menu
  31.  
  32.     Write-Host Welcome to $prefix!
  33.     Write-Host ""
  34.     Write-Host Let me get to know about your server better
  35.     Write-Host ""
  36.     $jarFile = Read-Host –Prompt "Enter your server's .jar file w/o the extension"
  37.     $minecraftVersion = Read-Host -Prompt "Enter your server's Minecraft version"
  38.  
  39.     Create-Config($jarFile, $minecraftVersion)
  40.     Write-Host Basic Setup Complete!
  41.  
  42.     Write-Host Moving to main menu..
  43.     #Main-Menu
  44. }
  45.  
  46. function Main-Menu (){
  47.     $settings = Import-Clixml -Path $configPath
  48.  
  49.     $ui.WindowTitle = "$prefix+: Main Menu"
  50.     Clear-Host
  51.     Write-Host "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# Main Menu #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  52.     Write-Host "1. Start The Server"
  53.     Write-Host "2. Settings"
  54.     Write-Host "3. Exit"
  55.     $mainMenuInput = Read-Host "Please make a selection: "
  56.     if(mainMenuInput != ){
  57.         Write-Host "Invalid Choice!"
  58.     }
  59.  
  60. }
  61.  
  62. function Start-Server(){
  63.     $consoleServerPrefix = "[+$consoleName+]:"
  64.     $ui.WindowTitle = "$prefix+: Server Running (Jar: $settings.server_jar, MC $settings.minecraftVersion)"
  65.     Clear-Host
  66.     Write-Host "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# Main Menu #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  67.     Write-Host "$consoleServerPrefix Server Starting!"
  68.    
  69.     #-#-#-#-# Ngrok Checking here #-#-#-#-#
  70.     Write-Host "$consoleServerPrefix Checking for Ngrok process..."
  71.  
  72.     #Already Started
  73.     Write-Host "$consoleServerPrefix Ngrok is Already Running! Skipping Ngrok Startup..."
  74.  
  75.     #Not Started
  76.     Write-Host "$consoleServerPrefix Ngrok Not Running! Starting Ngrok..."
  77.     start powershell {ngrok tcp 25565}
  78.     Write-Host "$consoleServerPrefix Ngrok Started!"
  79.     #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  80.  
  81.     Write-Host "$consoleServerPrefix Loading Java Arguments..."
  82.    
  83.     $settings = Import-Clixml -Path $configPath
  84.     $server = $currentLocation+'\forge.jar'
  85.     java -Xms1G -Xmx1G -jar C:\Users\novag\Documents\Powershell\forge.jar -o true
  86.  
  87.     Write-Host "Server is ending"
  88. }
  89.  
  90. function Change-Minecraft-Version(){
  91.    
  92.  
  93. }
  94.  
  95. function Change-RAM(){
  96.  
  97. }
  98.  
  99. function Change-Arguments(){
  100.  
  101. }
  102.  
  103. function Factory-Reset(){
  104.  
  105. }
  106.  
  107. function Settings-Menu(){
  108.  
  109.     $ui.WindowTitle = "$prefix+: Settings Menu"
  110.     Clear-Host
  111.     Write-Host "#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# Settings Menu #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#"
  112.     Write-Host "1. Change Minecraft Version - Change What Version of Minecraft the Server is Using"
  113.     Write-Host "2. RAM Allocation - Set RAM Allocation (Advanced)"
  114.     Write-Host "3. Custom Arguments - Set custom arguments besides the RAM! (Advanced)"
  115.     Write-Host "4. Factory Reset [!!]"
  116.     Write-Host "5. Back To Main Menu"
  117.  
  118. }
  119.  
  120. #Function to quit the auto relaunch based on a time set.
  121. Function Set-Quit([int]$delay) {
  122.     Write-Host ""
  123.     Write-Host -background Red "Press q to quit - you have $delay seconds to decide"
  124.     Start-Sleep -s $delay
  125.  
  126.     If ($ui.KeyAvailable -and ("q" -eq $ui.ReadKey("IncludeKeyUp,NoEcho").Character)) {
  127.         Write-Host -foreground Red "Exiting Script..."
  128.         Return $true;
  129.     }
  130.    
  131.     Return $false
  132. }
  133.  
  134. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#   BEGIN FUNCTION CALLS   #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  135.  
  136.  
  137. #Main area of the script.  This launches all functions above (PowerShell needs the functions declared before they can be ran).
  138. #Keep looping until the user quits the script.
  139. Do {
  140.     Clear-Host
  141.    
  142.     #Import Variables
  143.  
  144.     If (!(Test-Path $configPath)) {
  145.         Setup-Prompt
  146.     }
  147.    
  148.     Main-Menu
  149.     switch($mainMenuInput){
  150.         '1' {
  151.              cls
  152.              Start-Server
  153.                 }
  154.             '2' {
  155.                     cls
  156.                     Settings-Menu
  157.                 }
  158.             '3' {
  159.                     cls
  160.                     break;
  161.                 }
  162.         }
  163.  
  164. } Until (Set-Quit (5))
  165.  
  166. Write-Host "Press any key to exit"
  167. $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") > $NULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement