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"
- $sleepTime = 5
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# 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"
- $ramDataType = Check-RAM-Type
- $maxRAM = Check-Integer "Please enter your maximum amount of RAM (Random Access Memory) to use"
- $fullRAM = -Join ($maxRAM, $ramDataType)
- $basicInfo = @{
- Jar_File = "$jarFile"
- Minecraft_Version = "$mcVersion"
- Java_Flags = "-Xmx$fullRAM"
- Server_Options = "-o true"
- }
- New-Item $configFileName -ItemType "file" | Out-Null
- $basicInfo | ConvertTo-Json | Add-Content $configFileName
- Write-Host ""
- Write-Host "Moving to Main Menu..." -BackgroundColor Red
- Sleep -Seconds $sleepTime
- Main-Menu
- }
- function Main-Menu() {
- 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 -ForegroundColor Red "Are you SURE you want to reset back to factory default? This process CANNOT be reversed!!"
- $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
- Remove-Item $configFileName
- Write-Host "Factory Reset Completed!"
- Write-Host ""
- Write-Host "Returning to First-Time Setup..." -BackgroundColor Red
- Sleep -Seconds $sleepTime
- }
- function Exit-Script(){
- Write-Host ""
- Write-Host "Exiting Script..." -BackgroundColor Red
- Start-Sleep -Seconds $sleepTime
- $quitConsole = $true
- }
- function Return-Main-Menu(){
- Write-Host ""
- Write-Host "Returning to Main Menu..." -BackgroundColor Red
- Sleep -Seconds $sleepTime
- Main-Menu
- }
- function Return-Settings-Menu(){
- Write-Host ""
- Write-Host "Returning to Settings Menu..." -BackgroundColor Red
- Sleep -Seconds $sleepTime
- Settings-Menu
- }
- function Invaild-Choice(){
- [Console]::Beep(1000, 100)
- Write-Host "INVALID CHOICE! PLEASE ENTER ONE OF THE CHOICES LISTED!" -ForegroundColor Red
- Sleep -Seconds $sleepTime
- }
- 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 $sleepTime
- $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){
- $data = ''
- $min = 1
- $max = [int]::MaxValue
- While(($null -eq $data) -or ($data -eq '') -or ($data -eq '0') -or (-not ($data -notmatch '[^\d]'))){
- [int]$data = Read-Host -Prompt $promptMessage
- 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 $sleepTime
- }elseif(-not ($data -notmatch '[^\d]')){
- Write-Output ''
- [Console]::Beep(1000, 100)
- Write-Host "The value [$data] MUST be an integer!" -ForegroundColor Red
- Sleep -Seconds $sleepTime
- }else{
- return $data
- }
- }
- }
- function Check-RAM-Type(){
- $ramType = ''
- $ValidChoices = ('M', 'G')
- While ($ramType -notin $ValidChoices){
- $ramType = (Read-Host -Prompt 'Would you like to use [M]egabytes or [G]igabytes?').ToUpper()
- if ($ramType -notin $ValidChoices)
- {
- Invaild-Choice
- $ramType = ''
- }else{
- return $ramType
- }
- }
- }
- function Load-Variables(){
- $INFO = Get-Content -Path $configFileName -Raw | ConvertFrom-Json
- }
- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# BEGIN FUNCTION CALLS #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
- Do{
- Clear-Host
- #-#-#-#-# Setup Checking here #-#-#-#-#
- If (!(Test-Path $configFileName)) {
- Setup-Console
- }else{
- #Load data from JSON
- 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