<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$project = 'paper'; // or waterfall
$version = getLatestVersion($project);
$build = getLatestBuild($project, $version);
$fileName = getLatestDownload($project, $version, $build);
$downloadURL = "https://papermc.io/api/v2/projects/{$project}/versions/{$version}/builds/{$build}/downloads/{$fileName}";
header("Content-Disposition: attachment; filename*=UTF-8''paper-latest.jar");
header('Content-Type: application/java-archive');
echo file_get_contents($downloadURL);
function getLatestDownload($projectName, $version, $build){
$downloadStr = file_get_contents('https://papermc.io/api/v2/projects/'.$projectName.'/versions/'.$version.'/builds/'.$build);
$downloads = json_decode($downloadStr);
return $downloads->downloads->application->name;
}
function getLatestBuild($projectName, $version){
$buildsStr = file_get_contents('https://papermc.io/api/v2/projects/'.$projectName.'/versions/'.$version);
$builds = json_decode($buildsStr);
$latestBuild = $builds->builds[count($builds->builds)-1];
return $latestBuild;
}
function getLatestVersion($projectName){
$versions = file_get_contents('https://papermc.io/api/v2/projects/'.$projectName);
$versionJson = json_decode($versions);
$numVersions = count($versionJson->versions) - 1;
$latestVersion = $versionJson->versions[$numVersions];
return $latestVersion;
}
Comments