Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# VARIABLE DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- $currentLocation = Split-Path -parent $PSCommandPath
- $ui = (Get-Host).UI.RawUI
- $consoleName = "Console Master"
- $consoleVersion = '1.0'
- $prefix = "$consoleName $consoleVersion"
- $quitConsole = $false
- $configFileName = "config.json"
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# POWERSHELL CUSTOMIZATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- $ui.WindowTitle = "$prefix"
- Set-Location $currentLocation
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# FUNCTION DECLARATION #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- function Setup-Console(){
- Clear-Host
- $ui.WindowTitle = "$prefix+: Server Running (Jar: , MC )"
- Write-Host "Welcome To $consoleName!!"
- Write-Host ''
- $jarFile = Check-Jar "Please enter the name of the server's .jar file (w/o the extension)"
- $mcVersion = Check-Version "Please enter the Minecraft version your server is using"
- $maxRAM = Check-Integer "Please enter your maximum amount of RAM (Random Access Memory) to use"
- $basicInfo = @{
- Jar_File = "$jarFile"
- Minecraft_Version = "$mcVersion"
- Java_Flags = "-Xmx$maxRAM"
- Server_Options = "-o true"
- }
- New-Item $configFileName -ItemType "file" | Out-Null
- $basicInfo | ConvertTo-Json | Add-Content $configFileName
- }
- function Main-Menu() {
- #Load data from JSON
- $INFO = Get-Content -Path $configFileName -Raw | ConvertFrom-Json
- Clear-Host
- Write-Host @"
- ---------------------------------- Main Menu ----------------------------------
- 1. Start Server and Ngrok
- 2. Configurations Menu
- 3. Exit the Console
- -------------------------------------------------------------------------------
- "@
- $answer = Read-Host "Please Make a Selection"
- switch($answer){
- '1' {
- Clear-Host
- Start-Server
- }
- '2' {
- Clear-Host
- Settings-Menu
- }
- '3' {
- Exit-Script
- }
- default {
- Invaild-Choice
- Main-Menu
- }
- }
- }
- function Start-Server(){
- $consoleServerPrefix = "["+$consoleName+"]:"
- $ui.WindowTitle = "$prefix+: Server Running (Jar: , MC )"
- Write-Host @"
- ------------------------------- SERVER LOG START -------------------------------
- $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..."
- #start-process java -ArgumentList '-Xms1G -Xmx1G -jar C:\Users\novag\Documents\Powershell\forge.jar' -Wait -NoNewWindow
- java $INFO.Java_Flags -jar $INFO.Jar_File $INFO.Server_Options
- }
- function Settings-Menu() {
- Clear-Host
- Write-Host @"
- -------------------------------- Settings Menu --------------------------------
- 1. Change Version - Change the saved Minecraft version to match
- what the jar file uses
- 2. RAM Allocation - Set the amount of RAM (Random Access Memory)
- to reserve to the server [!]
- 3. Custom Arguments - Set custom arguments besides the RAM [!!]
- 4. Factory Reset - Erase all user defined settings and boot to
- first-time setup [!!!]
- 5. Return To Main Menu
- -------------------------------------------------------------------------------
- "@
- $answer = Read-Host "Please Make a Selection"
- switch($answer){
- '1' {
- Clear-Host
- Change-Minecraft-Version
- }
- '2' {
- Clear-Host
- Change-RAM
- }
- '3' {
- Clear-Host
- Confirm-Change-Args
- }
- '4' {
- Clear-Host
- Confirm-Factory-Reset
- }
- '5' {Return-Main-Menu}
- default {
- Invaild-Choice
- Settings-Menu
- }
- }
- }
- function Change-Minecraft-Version(){
- }
- function Change-RAM(){
- #Write-Host "Please Enter Your Minimum Amount Of RAM To Use Followed By 'M' For Megabytes Or 'G' For Gigabytes"
- }
- function Confirm-Change-Args(){
- }
- function Confirm-Factory-Reset(){
- Write-Host "Are you SURE you want to reset back to factory default? This process CANNOT be reversed!!" -ForegroundColor Red
- $answer = Read-Host "(Y)es or (N)o"
- switch($answer.ToUpper()){
- 'Y' {
- Clear-Host
- Perform-Factory-Reset
- }
- 'N' {
- Clear-Host
- Return-Settings-Menu
- }
- default {
- Invaild-Choice
- Confirm-Factory-Reset
- }
- }
- }
- function Perform-Factory-Reset(){
- Write-Host "Deleting Preferences..." -BackgroundColor Red
- #Delete Preference Method Here
- Write-Host "Factory Reset Completed!"
- Write-Host ""
- Write-Host "Returning to First-Time Setup..." -BackgroundColor Red
- Sleep -Seconds 2
- Setup-Console
- }
- function Exit-Script(){
- Write-Host ""
- Write-Host "Exiting Script..." -BackgroundColor Red
- Start-Sleep -Seconds 5
- $quitConsole = $true
- }
- function Return-Main-Menu(){
- Write-Host ""
- Write-Host "Returning to Main Menu..." -BackgroundColor Red
- Sleep -Seconds 2
- Main-Menu
- }
- function Return-Settings-Menu(){
- Write-Host ""
- Write-Host "Returning to Settings Menu..." -BackgroundColor Red
- Sleep -Seconds 2
- Settings-Menu
- }
- function Invaild-Choice(){
- [Console]::Beep(1000, 100)
- Write-Host "INVALID CHOICE! PLEASE ENTER ONE OF THE CHOICES LISTED!" -ForegroundColor Red
- Sleep -Seconds 2
- }
- function Check-Jar([string]$promptMessage){
- Do{
- [string]$data = Read-Host -Prompt $promptMessage
- if ((-not $null -eq $data) -and (-not $data -eq '')){
- return $data+'.jar'
- $loop = $false
- }else{
- Write-Output ''
- [Console]::Beep(1000, 100)
- Write-Host "You cannot enter a null/empty name!" -ForegroundColor Red
- Sleep -Seconds 2
- $loop = $true
- }
- } Until($loop = $false)
- }
- function Check-Version([string]$promptMessage){
- Do{
- $data = Read-Host -Prompt $promptMessage
- $minVer = [version]'1.0.0'
- $maxVer = [version]'999.999.999'
- if (($minVer -le $data) -and ($data -le $maxVer) -and ($data.Revision -lt 0)){
- return $data
- $loop = $false
- }else{
- [Console]::Beep(1000, 100)
- Write-Host "The value [$data] MUST be a version (major, minor, build) ranging between $min to $max!" -ForegroundColor Red
- $loop = $true
- }
- }Until($loop = $false)
- }
- function Check-Integer([string]$promptMessage){
- While($loopRAM = $false){
- $answerRAM = Read-Host -Prompt "Would you like to use [G]igabytes or [M]egabytes?"
- switch($answerRAM.ToUpper()){
- 'M' {
- $ramType = "m".ToUpper()
- $loopRAM = $false
- }
- 'G' {
- $ramType = "g".ToUpper()
- $loopRAM = $false
- }
- default {
- Invaild-Choice
- $loopRAM = $true
- }
- }
- }Until($loopRAM = $false)
- Do{
- [int]$data = Read-Host -Prompt $promptMessage
- $min = 1
- $max = [int]::MaxValue
- if(($null -eq $data) -or ($data -eq '') -or ($data -eq '0')){
- Write-Host ''
- [Console]::Beep(1000, 100)
- Write-Host "The value [$data] cannot be null, empty or 0!" -ForegroundColor Red
- Sleep -Seconds 2
- $loop = $true
- }
- if(-not ($data -notmatch '[^\d]')){
- Write-Output ''
- [Console]::Beep(1000, 100)
- Write-Host "The value [$data] MUST be an integer!" -ForegroundColor Red
- Sleep -Seconds 2
- Setup-Console
- $loop = $true
- }
- #$result = -Join ($data, $ramType)
- #return $result
- return $data
- $loop = $false
- }Until($loop = $false)
- }
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# BEGIN FUNCTION CALLS #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- Do{
- Clear-Host
- #-#-#-#-# Setup Checking here #-#-#-#-#
- If (!(Test-Path $configFileName)) {
- Setup-Console
- }else{
- Main-Menu
- }
- #If there are no basic files
- #If there are basic files
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- } Until ($quitConsole = $true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement