@@ -78,26 +78,54 @@ PROJECT="paper"
7878MINECRAFT_VERSION=" \{LATEST_PAPER_RELEASE}"
7979USER_AGENT=" cool-project/1.0.0 (contact@me.com)"
8080
81- # First check if the version exists
82- VERSION_CHECK =$( curl -s -H " User-Agent: $USER_AGENT " https://fill.papermc.io/v3/projects/${PROJECT} /versions/${MINECRAFT_VERSION} /builds)
81+ # First check if the requested version has a stable build
82+ BUILDS_RESPONSE =$( curl -s -H " User-Agent: $USER_AGENT " https://fill.papermc.io/v3/projects/${PROJECT} /versions/${MINECRAFT_VERSION} /builds)
8383
8484# Check if the API returned an error
85- if echo " $VERSION_CHECK " | jq -e ' .ok == false' > /dev/null 2>&1 ; then
86- ERROR_MSG=$( echo " $VERSION_CHECK " | jq -r ' .message // "Unknown error"' )
85+ if echo " $BUILDS_RESPONSE " | jq -e ' .ok == false' > /dev/null 2>&1 ; then
86+ ERROR_MSG=$( echo " $BUILDS_RESPONSE " | jq -r ' .message // "Unknown error"' )
8787 echo " Error: $ERROR_MSG "
8888 exit 1
8989fi
9090
91- # Get the download URL directly, or null if no stable build exists
92- PAPERMC_URL=$( curl -s -H " User-Agent: $USER_AGENT " https://fill.papermc.io/v3/projects/${PROJECT} /versions/${MINECRAFT_VERSION} /builds | \
93- jq -r ' first(.[] | select(.channel == "STABLE") | .downloads."server:default".url) // "null"' )
91+ # Try to get a stable build URL for the requested version
92+ PAPERMC_URL=$( echo " $BUILDS_RESPONSE " | jq -r ' first(.[] | select(.channel == "STABLE") | .downloads."server:default".url) // "null"' )
93+ FOUND_VERSION=" $MINECRAFT_VERSION "
94+
95+ # If no stable build for requested version, find the latest version with a stable build
96+ if [ " $PAPERMC_URL " == " null" ]; then
97+ echo " No stable build for version $MINECRAFT_VERSION , searching for latest version with stable build..."
98+
99+ # Get all versions for the project (using the same endpoint structure as the "Getting the latest version" example)
100+ # The versions are organized by version group, so we need to extract all versions from all groups
101+ # Then sort them properly as semantic versions (newest first)
102+ VERSIONS=$( curl -s -H " User-Agent: $USER_AGENT " https://fill.papermc.io/v3/projects/${PROJECT} | \
103+ jq -r ' .versions | to_entries[] | .value[]' | \
104+ sort -V -r)
105+
106+ # Iterate through versions to find one with a stable build
107+ for VERSION in $VERSIONS ; do
108+ VERSION_BUILDS=$( curl -s -H " User-Agent: $USER_AGENT " https://fill.papermc.io/v3/projects/${PROJECT} /versions/${VERSION} /builds)
109+
110+ # Check if this version has a stable build
111+ STABLE_URL=$( echo " $VERSION_BUILDS " | jq -r ' first(.[] | select(.channel == "STABLE") | .downloads."server:default".url) // "null"' )
112+
113+ if [ " $STABLE_URL " != " null" ]; then
114+ PAPERMC_URL=" $STABLE_URL "
115+ FOUND_VERSION=" $VERSION "
116+ echo " Found stable build for version $VERSION "
117+ break
118+ fi
119+ done
120+ fi
94121
95122if [ " $PAPERMC_URL " != " null" ]; then
96123 # Download the latest Paper version
97124 curl -o server.jar $PAPERMC_URL
98- echo " Download completed"
125+ echo " Download completed (version: $FOUND_VERSION ) "
99126else
100- echo " No stable build for version $MINECRAFT_VERSION found :("
127+ echo " No stable builds available for any version :("
128+ exit 1
101129fi
102130```
103131
@@ -108,16 +136,22 @@ do not receive support.
108136## GraphQL API examples
109137
110138Fill also supports a GraphQL API, which can be accessed at ` https://fill.papermc.io/graphql ` .
139+ Fill's GraphQL API uses standard pagination, which you can learn more about [ here] ( https://graphql.org/learn/pagination/ ) .
111140
112141A built-in GraphQL playground is available at https://fill.papermc.io/graphiql?path=/graphql .
113142Common API tools such as Postman will introspect the API and provide a UI for building queries.
114143
115144### Getting the latest version
116145``` graphql
117146query LatestVersion {
118- project (id : " paper" ) {
119- versions (last : 1 ) {
120- id
147+ project (key : " paper" ) {
148+ key
149+ versions (first : 1 , orderBy : {direction : DESC }) {
150+ edges {
151+ node {
152+ key
153+ }
154+ }
121155 }
122156 }
123157}
@@ -130,11 +164,16 @@ query LatestVersion {
130164{
131165 "data" : {
132166 "project" : {
133- "versions" : [
134- {
135- "id" : " 1.21.6"
136- }
137- ]
167+ "key" : " paper" ,
168+ "versions" : {
169+ "edges" : [
170+ {
171+ "node" : {
172+ "key" : " 1.21.11"
173+ }
174+ }
175+ ]
176+ }
138177 }
139178 }
140179}
@@ -145,10 +184,20 @@ query LatestVersion {
145184### Getting the latest stable build number
146185``` graphql
147186query LatestStableBuild {
148- project (id : " paper" ) {
149- versions (last : 1 ) {
150- builds (filterBy : { channel : STABLE }, last : 1 ) {
151- id
187+ project (key : " paper" ) {
188+ key
189+ versions (first : 1 , orderBy : {direction : DESC }) {
190+ edges {
191+ node {
192+ key
193+ builds (filterBy : { channel : STABLE }, first : 1 , orderBy : { direction : DESC }) {
194+ edges {
195+ node {
196+ number
197+ }
198+ }
199+ }
200+ }
152201 }
153202 }
154203 }
@@ -162,15 +211,25 @@ query LatestStableBuild {
162211{
163212 "data" : {
164213 "project" : {
165- "versions" : [
166- {
167- "builds" : [
168- {
169- "id" : 46
214+ "key" : " paper" ,
215+ "versions" : {
216+ "edges" : [
217+ {
218+ "node" : {
219+ "key" : " 1.21.10" ,
220+ "builds" : {
221+ "edges" : [
222+ {
223+ "node" : {
224+ "number" : 48
225+ }
226+ }
227+ ]
228+ }
170229 }
171- ]
172- }
173- ]
230+ }
231+ ]
232+ }
174233 }
175234 }
176235}
@@ -181,11 +240,27 @@ query LatestStableBuild {
181240### Getting the latest stable build download URL
182241``` graphql
183242query LatestStableBuildDownloadURL {
184- project (id : " paper" ) {
185- versions (last : 1 ) {
186- builds (filterBy : { channel : STABLE }, last : 1 ) {
187- download (name : " server:default" ) {
188- url
243+ project (key : " paper" ) {
244+ key
245+ versions (first : 1 , orderBy : {direction : DESC }) {
246+ edges {
247+ node {
248+ key
249+ builds (filterBy : { channel : STABLE }, first : 1 , orderBy : { direction : DESC }) {
250+ edges {
251+ node {
252+ number
253+ download (key : " server:default" ) {
254+ name
255+ url
256+ checksums {
257+ sha256
258+ }
259+ size
260+ }
261+ }
262+ }
263+ }
189264 }
190265 }
191266 }
@@ -200,17 +275,33 @@ query LatestStableBuildDownloadURL {
200275{
201276 "data" : {
202277 "project" : {
203- "versions" : [
204- {
205- "builds" : [
206- {
207- "download" : {
208- "url" : " https://fill-data.papermc.io/v1/objects/bfca155b4a6b45644bfc1766f4e02a83c736e45fcc060e8788c71d6e7b3d56f6/paper-1.21.6-46.jar"
278+ "key" : " paper" ,
279+ "versions" : {
280+ "edges" : [
281+ {
282+ "node" : {
283+ "key" : " 1.21.10" ,
284+ "builds" : {
285+ "edges" : [
286+ {
287+ "node" : {
288+ "number" : 48 ,
289+ "download" : {
290+ "name" : " paper-1.21.10-48.jar" ,
291+ "url" : " https://fill-data.papermc.io/v1/objects/bfca155b4a6b45644bfc1766f4e02a83c736e45fcc060e8788c71d6e7b3d56f6/paper-1.21.10-48.jar" ,
292+ "checksums" : {
293+ "sha256" : " bfca155b4a6b45644bfc1766f4e02a83c736e45fcc060e8788c71d6e7b3d56f6"
294+ },
295+ "size" : 54185955
296+ }
297+ }
298+ }
299+ ]
209300 }
210301 }
211- ]
212- }
213- ]
302+ }
303+ ]
304+ }
214305 }
215306 }
216307}
0 commit comments