Skip to content

Instantly share code, notes, and snippets.

@HBIDamian
Last active February 16, 2025 00:52
Show Gist options
  • Save HBIDamian/9668a6173d87d11d92a21e8f63080fb4 to your computer and use it in GitHub Desktop.
Save HBIDamian/9668a6173d87d11d92a21e8f63080fb4 to your computer and use it in GitHub Desktop.
Run Down Builder for PocketMine-MP (PowerShell).
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
$host.ui.RawUI.WindowTitle = "Run Down PocketMine-MP Builder"
# Global Variables
$global:repoUrl = "https://github.com/pmmp/PocketMine-MP.git"
$global:branch = "stable" # You can change this to any branch or fork URL
$global:PHPVer = "8.3" # Ex: 8.2, 8.3, etc.
$global:PMMPVer = "PM5"
function PreScript {
Clear-Host
SplashText
GetTimeStamp; Read-Host -Prompt "Press Enter to continue"
Write-Host ""
detectDependencies
Write-Host ""
BuildPocketMine
}
function detectDependencies {
# Detect Git Installation
if (-not (Test-Path "C:\Program Files\Git\cmd\git.exe")) {
GetTimeStamp; Write-Host "Git is not installed on your system." -ForegroundColor Red
GetTimeStamp; Write-Host "Please install Git from https://git-scm.com/downloads" -ForegroundColor DarkRed
GetTimeStamp; Read-Host -Prompt "Press Enter to exit"
exit
}
# Detect PHP Installation
if (-not (Test-Path ".\bin\php\php.exe")) {
GetTimeStamp; Write-Host "PHP Binaries is not installed in the local directory." -ForegroundColor Red
DownloadPHPBins
} else {
$phpVersion = & .\bin\php\php.exe -v | Select-String -Pattern "PHP ([0-9]+\.[0-9]+\.[0-9]+)"
if ($phpVersion.Matches.Groups[1].Value -lt "8.2.0") {
GetTimeStamp; Write-Host "PHP version is lower than 8.2.0." -ForegroundColor Red
GetTimeStamp; Write-Host "Please download PHP 8.2.0 or higher from https://github.com/pmmp/PHP-Binaries/releases and extract it to the local directory." -ForegroundColor DarkRed
GetTimeStamp; Read-Host -Prompt "Press Enter to exit"
exit
}
}
# Detect Composer Installation
if (-not (Test-Path ".\composer.phar")) {
GetTimeStamp; Write-Host "Composer is not installed in the local directory." -ForegroundColor Red
DownloadComposer
}
# Check if /src/PocketMine.php exists
if (-not (Test-Path ".\src\PocketMine.php")) {
GetTimeStamp; Write-Host "PocketMine-MP source code is not found in the local directory." -ForegroundColor Red
CloneSourceCode
}
}
function DownloadPHPBins {
# Download PHP
# https://github.com/pmmp/PHP-Binaries/releases/download/php-8.3-latest/PHP-Windows-x64-PM5.zip
$phpUrl = "https://github.com/pmmp/PHP-Binaries/releases/download/$($global:PMMPVer.toLower())-php-$($global:PHPVer)-latest/PHP-$($global:PHPVer)-Windows-x64-$($global:PMMPVer).zip"
$phpPath = ".\PHP-Windows-x64-$global:PMMPVer.zip"
GetTimeStamp; Write-Host "Downloading PHP Binaries..." -ForegroundColor White
Invoke-WebRequest -Uri $phpUrl -OutFile $phpPath
# Extract the downloaded archive to the local directory
Expand-Archive -Path $phpPath -DestinationPath .\ -Force
GetTimeStamp; Write-Host "PHP downloaded and extracted." -ForegroundColor Green
# Remove the downloaded archive
GetTimeStamp; Remove-Item -Path $phpPath -Force
}
function DownloadComposer {
# Download Composer
GetTimeStamp; Write-Host "Downloading Composer..." -ForegroundColor White
$composerUrl = "https://getcomposer.org/composer.phar"
Invoke-WebRequest -Uri $composerUrl -OutFile ".\composer.phar"
GetTimeStamp; Write-Host "Composer downloaded." -ForegroundColor Green
}
function CloneSourceCode {
GetTimeStamp; Write-Host "Downloading PocketMine-MP source code..." -ForegroundColor White
# git clone -b $branch $repoUrl ./tmp
git clone -b $global:branch $global:repoUrl ./tmp
# Move everything from the tmp directory to the current directory
GetTimeStamp; Move-Item -Path .\tmp\* -Destination .\ -Force
# Remove the tmp directory
GetTimeStamp; Remove-Item -Path .\tmp -Recurse -Force
GetTimeStamp; Write-Host "Source code downloaded." -ForegroundColor Green
}
function SplashText {
Write-Host " _____________________ _________ " -ForegroundColor Red
Write-Host " | ___ \ _ \ ___ \ \/ || ___ \ " -ForegroundColor DarkYellow
Write-Host " | |_/ / | | | |_/ / . . || |_/ / " -ForegroundColor Yellow
Write-Host " | /| | | | __/| |\/| || ___ \ " -ForegroundColor Green
Write-Host " | |\ \| |/ /| | | | | || |_/ / " -ForegroundColor DarkCyan
Write-Host " \_| \_|___/ \_| \_| |_/\____/ " -ForegroundColor Magenta
Write-Host ""
Write-Host "Run Down PocketMine-MP Builder:" -ForegroundColor Magenta -NoNewline; Write-Host " Made by HBIDamian" -ForegroundColor DarkCyan
Write-Host "This is a hacky way of building PocketMine-MP." -ForegroundColor DarkMagenta
Write-Host ""
}
function GetTimeStamp {
Write-Host "[$((Get-Date -Format 'HH:mm:ss:fff'))] " -ForegroundColor White -NoNewline
}
function BuildPocketMine {
# Run Composer install
GetTimeStamp; Write-Host " Running Composer..." -ForegroundColor White
try {
# If $global:branch is not "stable", we need to run composer install with --no-dev
if ($global:branch -ne "stable") {
.\bin\php\php.exe .\composer.phar install --no-dev --classmap-authoritative
} else {
.\bin\php\php.exe .\composer.phar install
}
if ($LASTEXITCODE -ne 0) {
throw "Composer install failed with exit code $LASTEXITCODE"
}
} catch {
GetTimeStamp; Write-Host " Composer install failed: $_" -ForegroundColor Red
return
}
# Run Composer make-server
GetTimeStamp; Write-Host " Building PocketMine-MP.phar..." -ForegroundColor White
try {
.\bin\php\php.exe .\composer.phar make-server
if ($LASTEXITCODE -ne 0) {
throw "Composer make-server failed with exit code $LASTEXITCODE"
}
GetTimeStamp; Write-Host "PocketMine-MP.phar built successfully." -ForegroundColor Green
GetTimeStamp; Write-Host "You can find the built PocketMine-MP.phar in the local directory." -ForegroundColor Green
} catch {
GetTimeStamp; Write-Host " Composer make-server failed: $_" -ForegroundColor Red
return
}
}
PreScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment