@@ -42,15 +42,10 @@ public class PaperVersionFetcher implements VersionFetcher {
4242 private static final int DISTANCE_UNKNOWN = -2 ;
4343 private static final String DOWNLOAD_PAGE = "https://papermc.io/downloads/paper" ;
4444 private static final String REPOSITORY = "PaperMC/Paper" ;
45- private static final ServerBuildInfo BUILD_INFO ;
46- private static final String USER_AGENT ;
45+ private static final ServerBuildInfo BUILD_INFO = ServerBuildInfo . buildInfo () ;
46+ private static final String USER_AGENT = BUILD_INFO . brandName () + "/" + BUILD_INFO . asString ( VERSION_SIMPLE ) + " (https://papermc.io)" ;
4747 private static final Gson GSON = new Gson ();
4848
49- static {
50- BUILD_INFO = ServerBuildInfo .buildInfo ();
51- USER_AGENT = BUILD_INFO .brandName () + "/" + BUILD_INFO .asString (VERSION_SIMPLE ) + " (https://papermc.io)" ;
52- }
53-
5449 @ Override
5550 public long getCacheTime () {
5651 return 720000 ;
@@ -199,20 +194,19 @@ private static Optional<MinecraftVersionFetcher> fetchMinecraftVersionList() {
199194
200195 private static int fetchDistanceFromSiteApi (final int jenkinsBuild ) {
201196 try {
202- final URL buildsUrl = URI .create ("https://fill.papermc.io/v3/projects/paper/versions/" + PaperVersionFetcher .BUILD_INFO .minecraftVersionId ()).toURL ();
197+ final URL buildsUrl = URI .create ("https://fill.papermc.io/v3/projects/paper/versions/" + PaperVersionFetcher .BUILD_INFO .minecraftVersionId () + "/builds" ).toURL ();
203198 final HttpURLConnection connection = (HttpURLConnection ) buildsUrl .openConnection ();
204199 connection .setConnectTimeout (5000 );
205200 connection .setReadTimeout (5000 );
206201 connection .setRequestProperty ("User-Agent" , PaperVersionFetcher .USER_AGENT );
207202 connection .setRequestProperty ("Accept" , "application/json" );
208203 try (final BufferedReader reader = new BufferedReader (new InputStreamReader (connection .getInputStream (), StandardCharsets .UTF_8 ))) {
209- final JsonObject json = GSON .fromJson (reader , JsonObject .class );
210- final JsonArray builds = json .getAsJsonArray ("builds" );
204+ final JsonArray builds = GSON .fromJson (reader , JsonArray .class );
211205 final int latest = StreamSupport .stream (builds .spliterator (), false )
212- .mapToInt (JsonElement :: getAsInt )
206+ .mapToInt (build -> build . getAsJsonObject (). get ( "id" ). getAsInt () )
213207 .max ()
214208 .orElseThrow ();
215- return latest - jenkinsBuild ;
209+ return Math . max ( latest - jenkinsBuild , 0 ) ;
216210 } catch (final JsonSyntaxException ex ) {
217211 LOGGER .error ("Error parsing json from Paper's downloads API" , ex );
218212 return DISTANCE_ERROR ;
0 commit comments