Adds Powershell scripts to tools.
This commit is contained in:
20
tools/powershell/Build-Plugin.ps1
Normal file
20
tools/powershell/Build-Plugin.ps1
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Find project root (two directories above this script)
|
||||||
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
||||||
|
|
||||||
|
# Save current location and change to project root
|
||||||
|
Push-Location $ProjectRoot
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Build the project using Gradle
|
||||||
|
& ".\gradlew.bat" build
|
||||||
|
} finally {
|
||||||
|
# Always restore the original location
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
49
tools/powershell/Deploy-Plugin.ps1
Normal file
49
tools/powershell/Deploy-Plugin.ps1
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Check required environment variable
|
||||||
|
if (-not $env:MINECRAFT_SERVER_PATH) {
|
||||||
|
Write-Error "Error: MINECRAFT_SERVER_PATH environment variable is not set."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find project root (two directories above this script)
|
||||||
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
||||||
|
|
||||||
|
# Find the most recent plugin jar file
|
||||||
|
$LibsPath = Join-Path $ProjectRoot "build\libs"
|
||||||
|
$PluginJar = Get-ChildItem -Path "$LibsPath\*.jar" -ErrorAction SilentlyContinue |
|
||||||
|
Sort-Object LastWriteTime -Descending |
|
||||||
|
Select-Object -First 1
|
||||||
|
|
||||||
|
if (-not $PluginJar) {
|
||||||
|
Write-Error "Error: No plugin jar found in $LibsPath. Build the plugin first."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Optional: Warn if jar is older than any source file
|
||||||
|
$SourcePaths = @(
|
||||||
|
(Join-Path $ProjectRoot "src\main\java"),
|
||||||
|
(Join-Path $ProjectRoot "src\main\resources")
|
||||||
|
)
|
||||||
|
|
||||||
|
$NewerSourceFiles = Get-ChildItem -Path $SourcePaths -Recurse -File -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { $_.LastWriteTime -gt $PluginJar.LastWriteTime }
|
||||||
|
|
||||||
|
if ($NewerSourceFiles) {
|
||||||
|
Write-Host "Warning: The built plugin jar is older than some source files. Consider rebuilding." -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create plugins directory if it doesn't exist
|
||||||
|
$PluginsPath = Join-Path $env:MINECRAFT_SERVER_PATH "plugins"
|
||||||
|
if (-not (Test-Path $PluginsPath)) {
|
||||||
|
New-Item -ItemType Directory -Path $PluginsPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy the plugin jar to the plugins directory
|
||||||
|
Copy-Item -Path $PluginJar.FullName -Destination $PluginsPath -Force
|
||||||
|
Write-Host "Deployed $($PluginJar.Name) to $PluginsPath\"
|
||||||
34
tools/powershell/Start-Server.ps1
Normal file
34
tools/powershell/Start-Server.ps1
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Check required environment variables
|
||||||
|
if (-not $env:MINECRAFT_SERVER_PATH -or -not $env:MINECRAFT_SERVER_JAR) {
|
||||||
|
Write-Error "Error: MINECRAFT_SERVER_PATH and MINECRAFT_SERVER_JAR must be set."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Push-Location $env:MINECRAFT_SERVER_PATH
|
||||||
|
|
||||||
|
# Find running server process (java with the server jar)
|
||||||
|
$ServerProcess = Get-Process -Name "java" -ErrorAction SilentlyContinue | Where-Object {
|
||||||
|
$_.CommandLine -like "*$($env:MINECRAFT_SERVER_JAR)*"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ServerProcess) {
|
||||||
|
Write-Host "Minecraft server is running (PID: $($ServerProcess.Id)). Stopping it..."
|
||||||
|
Stop-Process -Id $ServerProcess.Id -Force
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
} else {
|
||||||
|
Write-Host "Minecraft server is not running."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start the server in a new window
|
||||||
|
try {
|
||||||
|
$ServerJob = Start-Process -FilePath "java" -ArgumentList "-jar", $env:MINECRAFT_SERVER_JAR -PassThru
|
||||||
|
Write-Host "Minecraft server started in new window with PID: $($ServerJob.Id)"
|
||||||
|
} finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
25
tools/powershell/Stop-Server.ps1
Normal file
25
tools/powershell/Stop-Server.ps1
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
# Set strict mode for better error handling
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Check required environment variables
|
||||||
|
if (-not $env:MINECRAFT_SERVER_PATH -or -not $env:MINECRAFT_SERVER_JAR) {
|
||||||
|
Write-Error "Error: MINECRAFT_SERVER_PATH and MINECRAFT_SERVER_JAR must be set."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find running server process (java with the server jar)
|
||||||
|
$ServerProcess = Get-Process -Name "java" -ErrorAction SilentlyContinue | Where-Object {
|
||||||
|
$_.CommandLine -like "*$($env:MINECRAFT_SERVER_JAR)*"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ServerProcess) {
|
||||||
|
Write-Host "Minecraft server is running (PID: $($ServerProcess.Id)). Stopping it..."
|
||||||
|
Stop-Process -Id $ServerProcess.Id -Force
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
Write-Host "Minecraft server stopped."
|
||||||
|
} else {
|
||||||
|
Write-Host "Minecraft server is not running."
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user