1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Paper(マイクラ鯖ソフト)の最新ビルドを自動で取得する

Posted at

はじめに

Minecraftのサーバーソフト、Paperの最新ビルドを自動でダウンロードする方法を紹介します。

使い道

  • サーバーの自動構築
  • 自動アップデート

自分はgradleのデバッグ環境の構築のとき必要になりました。

PaperMCのAPI

公式のDownloadAPIなるものがあるらしい。

どうやらこれで各バージョンごとのビルド一覧が取得できるようです。

APIの解説

PaperMCのAPI: https://api.papermc.io/v2/projects/paper

ここから具体的なバージョン番号やビルド番号を指定して具体的な情報を取得できます。今回は「最新ビルド」を取得するために、以下のAPIを利用します。

minecraftのバージョンからビルド一覧を取得: https://api.papermc.io/v2/projects/paper/versions/{version}

次のようなレスポンスが返ってきます。
buildsにビルド一覧が載っています。最新は一番数字が大きいものを取得すれば良いです。

{
  "project_id": "paper",
  "project_name": "Paper",
  "version": "{version}",
  "builds": [
    0, 1, 2, 3...
  ]
}

ダウンロードurl:
https://api.papermc.io/v2/projects/paper/versions/{version}/builds/{build}/downloads/paper-{version}-{build}.jar

例:
https://api.papermc.io/v2/projects/paper/versions/1.19.4/builds/550/downloads/paper-1.19.4-550.jar

APIを用いた自動ダウンロードのスクリプト

ChatGPTにShellスクリプトを書いてもらいました。

#!/bin/bash

# 任意のマイクラバージョンを指定
VERSION=1.20.1

# 最新ビルドを取得
BUILD=$(curl -s https://api.papermc.io/v2/projects/paper/versions/${VERSION} | jq -r '.builds[-1]')

# ビルドのjarファイルをダウンロード
curl -OL https://api.papermc.io/v2/projects/paper/versions/${VERSION}/builds/${BUILD}/downloads/paper-${VERSION}-${BUILD}.jar

まとめ

この記事では、MinecraftのPaperサーバーソフトウェアの最新ビルドを自動でダウンロードする方法をご紹介しました。もしかしたら最新ビルドを取得するAPIがあるかもしれません。その時はコメントいただけると幸いです。

ちなみにFoliaやWaterfallなど、PaperMCが開発しているソフトウェアであれば同じ手法で最新版を取得するすることができます。

参考リンク

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?