This is just a quick Post! I oftenly need a Minecraft Server that automatically downloads the newest Server file. Finding out the URL to that is usually a bit harder and requires a multistep script. I then simply created a PHP script, that redirects to the newest Minecraft Server file. The Link is the following:
https://tool.dhusch.de/mc-server-jar
This is the Source Code:
<?php
// Get the latest version_manifest.json
$manifestData = json_decode(file_get_contents("https://launchermeta.mojang.com/mc/game/version_manifest.json"), true);
// Get the latest release version number
$latestRelease = $manifestData['latest']['release'];
// Extract the latest_release_version.json URL
$manifestUrl = '';
foreach ($manifestData['versions'] as $version) {
if ($version['id'] === $latestRelease) {
$manifestUrl = $version['url'];
break;
}
}
if ($manifestUrl) {
// Get the latest_release_version.json
$versionData = json_decode(file_get_contents($manifestUrl), true);
// Extract the latest server download URL from the JSON
$downloadUrl = $versionData['downloads']['server']['url'];
// Redirect to the latest server.jar download URL
header("Location: $downloadUrl");
exit;
} else {
echo "Couldn't find the manifest URL for the latest version.\n";
}
?>
I created this script by using older bash scripts I already created for other Minecraft Projects. ChatGPT also helped me a little.
I hope this Code will help you to create an auto-updating Minecraft Server.