MinecraftStatus
Documentation

Check Minecraft status with Java

Copy this example, set an optional MINECRAFTSTATUS_API_KEY in the environment, and pass an edition plus address. The example preserves pending, quota and freshness boundaries.

Source

Java · anonymous by default
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public final class StatusExample {
  public static void main(String[] args) throws Exception {
    String base = System.getenv().getOrDefault("MINECRAFTSTATUS_API_BASE", "https://minecraftstatus.com");
    String edition = args.length > 0 ? args[0] : "java";
    String address = args.length > 1 ? args[1] : "play.example.net";
    String encoded = java.net.URLEncoder.encode(address, java.nio.charset.StandardCharsets.UTF_8).replace("+", "%20");
    HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(base + "/api/v1/status/" + edition + "?address=" + encoded))
        .header("Accept", "application/json");
    String key = System.getenv("MINECRAFTSTATUS_API_KEY");
    if (key != null && !key.isBlank()) builder.header("Authorization", "Bearer " + key);
    HttpResponse<String> response = HttpClient.newHttpClient().send(builder.GET().build(), HttpResponse.BodyHandlers.ofString());
    if (response.statusCode() == 429) throw new IllegalStateException("Rate limited; retry after " + response.headers().firstValue("Retry-After").orElse("unknown") + " seconds");
    if (response.statusCode() == 202) { System.out.println("Observation pending; poll the returned pollUrl: " + response.body()); return; }
    if (response.statusCode() >= 400) throw new IllegalStateException("MinecraftStatus API HTTP " + response.statusCode() + ": " + response.body());
    System.out.println(response.body());
    if (!response.body().contains("\"freshness\": \"fresh\"")) System.err.println("Freshness is not fresh; do not present the claim as current.");
  }
}

Run with an address argument such as java play.example.net. The source files are versioned alongside this documentation under examples/api/java/status.java.

Choose another language

Contract boundary

Every example branches on HTTP status first, prints a queued job receipt for 202, respects Retry-After for 429, and refuses to present stale or missing freshness as current.