Skip to content

Instantly share code, notes, and snippets.

@jasonw4331
Last active October 25, 2019 14:21
Show Gist options
  • Save jasonw4331/f3e8cdb10f0fc39c17835a4c1c2c0538 to your computer and use it in GitHub Desktop.
Save jasonw4331/f3e8cdb10f0fc39c17835a4c1c2c0538 to your computer and use it in GitHub Desktop.
A simple batch script for making installing PocketMine on windows easier
@echo off
TITLE PocketMine-MP Installer
cd /d %~dp0
if exist %~dp0PocketMine-MP\ goto PMSTART
mkdir PocketMine-MP
cd PocketMine-MP
powershell -command "& { iwr https://jenkins.pmmp.io/job/PocketMine-MP/Stable/artifact/PocketMine-MP.phar -OutFile PocketMine-MP.phar }"
powershell -command "& { iwr https://ci.appveyor.com/api/buildjobs/yjbqu49kp33aamli/artifacts/php-7.2.21-vc15-x64.zip -OutFile php-7.2.21-vc15-x64.zip }"
powershell -command "Expand-Archive -Path php-7.2.21-vc15-x64.zip -DestinationPath ."
start /w vc_redist.x64.exe
powershell -command "& { iwr https://raw.githubusercontent.com/pmmp/PocketMine-MP/master/start.cmd -OutFile start.cmd }"
powershell -command "& { iwr https://jenkins.pmmp.io/job/PocketMine-MP/lastStableBuild/artifact/build_info.json -OutFile old_build_info.json }"
powershell -command "& { iwr https://gist.githubusercontent.com/jasonwynn10/f3e8cdb10f0fc39c17835a4c1c2c0538/raw/9efb2acfa8c009020364702e7975916f0d96ac2f/start.ps1 -OutFile start.ps1 }"
mkdir plugins
powershell -command "& { iwr https://jenkins.pmmp.io/job/PocketMine-MP/Stable/artifact/DevTools.phar -OutFile plugins\devtools.phar }"
:PMSTART
echo Starting PocketMine-MP
pause
cls
cd %~dp0PocketMine-MP
.\start.cmd
@echo off
TITLE PocketMine-MP server software for Minecraft: Pocket Edition
cd /d %~dp0
set LOOP=true
set /A LOOPS=0
if exist bin\php\php.exe (
set PHPRC=""
set PHP_BINARY=bin\php\php.exe
) else (
set PHP_BINARY=php
)
if exist PocketMine-MP.phar (
set POCKETMINE_FILE=PocketMine-MP.phar
) else (
if exist src\PocketMine.php (
set POCKETMINE_FILE=src\PocketMine.php
) else (
echo "Couldn't find a valid PocketMine-MP installation"
pause
exit 1
)
)
if exist bin\mintty.exe (
start "" bin\mintty.exe -o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o Font="Consolas" -o FontHeight=10 -o CursorType=0 -o CursorBlinks=1 -h error -t "PocketMine-MP" -i bin/pocketmine.ico -w max %PHP_BINARY% %POCKETMINE_FILE% --enable-ansi %*
) else (
REM pause on exitcode != 0 so the user can see what went wrong
goto :start
)
:loop
if %LOOP% equ true (
echo Restarted %LOOPS% times.
echo To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart.
timeout 5
set /A LOOPS+=1
goto :start
) else (
exit 0
)
:start
%PHP_BINARY% -c bin\php %POCKETMINE_FILE% %* || pause
goto :loop
[CmdletBinding(PositionalBinding=$false)]
param (
[string]$php = "",
[switch]$Loop = $false,
[string]$file = "",
[string]$Update = $true,
[string][Parameter(ValueFromRemainingArguments)]$extraPocketMineArgs
)
if($php -ne ""){
$binary = $php
}elseif(Test-Path "bin\php\php.exe"){
$env:PHPRC = ""
$binary = "bin\php\php.exe"
}else{
$binary = "php"
}
if($file -eq ""){
if(Test-Path "PocketMine-MP.phar"){
$file = "PocketMine-MP.phar"
}elseif(Test-Path "src\PocketMine.php"){
$file = "src\PocketMine.php"
}else{
echo "Couldn't find a valid PocketMine-MP installation"
pause
exit 1
}
}
function StartServer{
$command = "powershell -NoProfile " + $binary + " " + $file + " " + $extraPocketMineArgs
iex $command
}
function UpdateServer{
(New-Object System.Net.WebClient).DownloadFile("https://jenkins.pmmp.io/job/PocketMine-MP/lastStableBuild/artifact/build_info.json", "$PSScriptRoot\build_info.json")
$json = Get-Content -Path "$PSScriptRoot\build_info.json"
$x = $json | ConvertFrom-Json
$new = $x.build_number
$json = Get-Content -Path "$PSScriptRoot\old_build_info.json"
$x = $json | ConvertFrom-Json
$old = $x.build_number
if($new -gt $old){
Remove-Item "$PSScriptRoot\PocketMine-MP.phar"
(New-Object System.Net.WebClient).DownloadFile("https://jenkins.pmmp.io/job/PocketMine-MP/lastStableBuild/artifact/PocketMine-MP.phar", "$PSScriptRoot\PocketMine-MP.phar")
}
Remove-Item "$PSScriptRoot\old_build_info.json"
Rename-Item -Path "$PSScriptRoot\build_info.json" -NewName "old_build_info.json"
}
$loops = 0
if($Update -eq $true){
UpdateServer
}
StartServer
while($Loop){
if($loops -ne 0){
echo ("Restarted " + $loops + " times")
}
$loops++
echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart."
echo ""
Start-Sleep 5
StartServer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment