Advertisement
NovaViper

Untitled

Jun 7th, 2017
280
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. $ui = (Get-Host).UI.RawUI
  5. $consoleName = "Console Master"
  6. $consoleVersion = '1.0'
  7. $prefix = "$consoleName $consoleVersion"
  8. $quitConsole = $false
  9. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# POWERSHELL CUSTOMIZATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  10. $ui.WindowTitle = "$prefix"
  11.  
  12. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# FUNCTION DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  13. function Setup-Console(){
  14.     Param (
  15.         [Parameter(Mandatory=$True, ValueFromPipeline)]
  16.         [ValidateNotNullOrEmpty()]
  17.         [string]$minecraftVersion
  18.     )
  19. }
  20.  
  21. function Main-Menu() {
  22.     Clear-Host
  23.     Write-Host @"
  24. ---------------------------------- Main Menu ----------------------------------
  25.  
  26.                    1. Start Server and Ngrok
  27.                    2. Configurations Menu
  28.                        
  29.                    3. Exit the Console
  30.  
  31. -------------------------------------------------------------------------------
  32. "@
  33.  
  34.     $answer = read-host "Please Make a Selection"
  35.     switch($answer){
  36.         '1' {
  37.             Clear-Host
  38.             Start-Server
  39.         }
  40.         '2' {
  41.             Clear-Host
  42.             Settings-Menu
  43.         }
  44.         '3' {
  45.             Exit-Script
  46.         }
  47.         default {
  48.             Invaild-Choice
  49.             Main-Menu
  50.         }
  51.     }
  52. }
  53.  
  54. function Start-Server(){
  55.     $consoleServerPrefix = "[+$consoleName+]:"
  56.     $ui.WindowTitle = "$prefix+: Server Running (Jar: , MC )"
  57.     Write-Host @"
  58. ------------------------------- SERVER LOG START -------------------------------
  59. $consoleServerPrefix Server Starting!"
  60. "@
  61.    #-#-#-#-# Ngrok Checking here #-#-#-#-#
  62.    Write-Host "$consoleServerPrefix Checking for Ngrok process..."
  63.  
  64.    #Already Started
  65.    Write-Host "$consoleServerPrefix Ngrok is Already Running! Skipping Ngrok Startup..."
  66.  
  67.    #Not Started
  68.    Write-Host "$consoleServerPrefix Ngrok Not Running! Starting Ngrok..."
  69.    start powershell {ngrok tcp 25565}
  70.    Write-Host "$consoleServerPrefix Ngrok Started!"
  71.    #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  72.  
  73.    Write-Host "$consoleServerPrefix Loading Java Arguments..."
  74.    cd $currentLocation
  75.    java -Xmx1G -jar forge.jar -o True
  76.    #java -Xms1G -Xmx1G -jar C:\Users\novag\Documents\Powershell\forge.jar
  77. }
  78.  
  79. function Settings-Menu() {
  80.    Clear-Host
  81.    Write-Host @"
  82. -------------------------------- Settings Menu --------------------------------
  83.  
  84.     1. Change Version - Change the saved Minecraft version to match
  85.                         what the jar file uses
  86.     2. RAM Allocation - Set the amount of RAM (Random Access Memory)
  87.                         to reserve to the server [!]
  88.     3. Custom Arguments - Set custom arguments besides the RAM [!!]
  89.     4. Factory Reset - Erase all user defined settings and boot to
  90.                         first-time setup [!!!]
  91.  
  92.     5. Return To Main Menu
  93.  
  94. -------------------------------------------------------------------------------
  95. "@
  96.  
  97.    $answer = read-host "Please Make a Selection"
  98.    switch($answer){
  99.        '1' {
  100.            Clear-Host
  101.            Change-Minecraft-Version
  102.        }
  103.        '2' {
  104.            Clear-Host
  105.            Change-RAM
  106.        }
  107.        '3' {
  108.            Clear-Host
  109.            Confirm-Change-Args
  110.        }
  111.        '4' {
  112.            Clear-Host
  113.             Confirm-Factory-Reset
  114.        }
  115.        '5' {Return-Main-Menu}
  116.        default {
  117.            Invaild-Choice
  118.            Settings-Menu
  119.        }
  120.    }
  121. }
  122.  
  123. function Change-Minecraft-Version(){
  124.    
  125.    Param (
  126.        [Parameter(Mandatory=$True, ValueFromPipeline)]
  127.        [ValidateNotNullOrEmpty()]
  128.        [string]$minecraftVersion
  129.    )
  130.  
  131.    Write-Host $minecraftVersion
  132.  
  133. }
  134.  
  135. function Change-RAM(){
  136.    #Write-Host "Please Enter Your Minimum Amount Of RAM To Use Followed By 'M' For Megabytes Or  'G' For Gigabytes"
  137.    
  138.    Param (
  139.        [ValidateRange(1, [int]::MaxValue)]
  140.        [Parameter(Mandatory=$True, ValueFromPipeline)]
  141.        [int]$ramMin,
  142.  
  143.        [ValidateRange(1, [int]::MaxValue)]
  144.        [Parameter(Mandatory=$True, ValueFromPipeline)]
  145.        [int]$ramMax
  146.    )
  147.  
  148.    Write-Host $ramMin, $ramMax
  149.  
  150. }
  151.  
  152. function Confirm-Change-Args(){
  153.  
  154. }
  155.  
  156. function Confirm-Factory-Reset(){
  157.    Write-Host "Are you SURE you want to reset back to factory default? This process CANNOT be reversed!!" -ForegroundColor Red
  158.    $answer = read-host "(Y)es or (N)o"
  159.    switch($answer){
  160.        'Y' {
  161.            Clear-Host
  162.            Preform-Factory-Reset
  163.        }
  164.        'y' {
  165.            Clear-Host
  166.            Preform-Factory-Reset
  167.        }
  168.        'N' {
  169.            Clear-Host
  170.            Return-Settings-Menu
  171.        }
  172.        'n' {
  173.            Clear-Host
  174.            Return-Settings-Menu
  175.        }
  176.        default {
  177.            Invaild-Choice
  178.            Confirm-Factory-Reset
  179.        }
  180.    }
  181. }
  182.  
  183. function Perform-Factory-Reset(){
  184.    Write-Host "Deleting Preferences..." -BackgroundColor Red
  185.    #Delete Preference Method Here
  186.    Write-Host "Factory Reset Completed!"
  187.    Write-Host ""
  188.    Write-Host "Returning to First-Time Setup..." -BackgroundColor Red
  189.    Sleep -Seconds 2
  190.    Setup-Console
  191. }
  192.  
  193.  
  194. function Exit-Script(){
  195.    Write-Host ""
  196.    Write-Host "Exiting Script..." -BackgroundColor Red
  197.    Start-Sleep -Seconds 5
  198.    $quitConsole = $true
  199. }
  200.  
  201. function Return-Main-Menu(){
  202.    Write-Host ""
  203.    Write-Host "Returning to Main Menu..." -BackgroundColor Red
  204.    Sleep -Seconds 2
  205.    Main-Menu
  206. }
  207.  
  208. function Return-Settings-Menu(){
  209.    Write-Host ""
  210.    Write-Host "Returning to Settings Menu..." -BackgroundColor Red
  211.    Sleep -Seconds 2
  212.    Settings-Menu
  213. }
  214.  
  215. function Invaild-Choice(){
  216.    Write-Warning "INVALID CHOICE! PLEASE ENTER ONE OF THE CHOICES LISTED!"
  217.    Sleep -Seconds 2
  218. }
  219.  
  220. #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#   BEGIN FUNCTION CALLS   #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  221.  
  222. Do{
  223.    #-#-#-#-# Setup Checking here #-#-#-#-#
  224.    #If there are no basic files
  225.    #Setup-Console
  226.  
  227.    #If there are basic files
  228.    Main-Menu
  229.    #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
  230. } Until ($quitConsole = $true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement