Live map: plugin/mod chunk+player sync, admin panel Live Map section, launcher transport
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DjMbLQujBHunCCu5GpsHaT
This commit is contained in:
14 files changed
+769
-8
No files matched your search
@@ -54,6 +54,41 @@ public final class PanelClient {
|
||||
}
|
||||
}
|
||||
|
||||
public HttpClient http() { return client; }
|
||||
public Settings settings() { return settings; }
|
||||
|
||||
private static JsonObject object(HttpResponse<String> response) throws IOException {
|
||||
if (response.statusCode() < 200 || response.statusCode() >= 300) {
|
||||
String msg = "HTTP " + response.statusCode();
|
||||
try {
|
||||
JsonObject err = JsonParser.parseString(response.body()).getAsJsonObject();
|
||||
if (err.has("message")) msg = err.get("message").getAsString();
|
||||
else if (err.has("error")) msg = err.get("error").getAsString();
|
||||
} catch (Exception ignored) {}
|
||||
throw new HttpFailure(response.statusCode(), msg);
|
||||
}
|
||||
try { return JsonParser.parseString(response.body()).getAsJsonObject(); }
|
||||
catch (RuntimeException e) { throw new IOException("Invalid panel response", e); }
|
||||
}
|
||||
|
||||
/** GET an endpoint under /api/server/v1/ that returns a JSON object. */
|
||||
public JsonObject get(String endpoint) throws IOException, InterruptedException {
|
||||
HttpRequest request = HttpRequest.newBuilder(URI.create(settings.panel() + "/api/server/v1/" + endpoint))
|
||||
.timeout(Duration.ofSeconds(15))
|
||||
.header("Authorization", "Bearer " + settings.token()).GET().build();
|
||||
return object(client.send(request, HttpResponse.BodyHandlers.ofString()));
|
||||
}
|
||||
|
||||
/** POST raw bytes (live map chunk batches and level.dat). */
|
||||
public JsonObject postBytes(String endpoint, byte[] body) throws IOException, InterruptedException {
|
||||
HttpRequest request = HttpRequest.newBuilder(URI.create(settings.panel() + "/api/server/v1/" + endpoint))
|
||||
.timeout(Duration.ofSeconds(60))
|
||||
.header("Authorization", "Bearer " + settings.token())
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.POST(HttpRequest.BodyPublishers.ofByteArray(body)).build();
|
||||
return object(client.send(request, HttpResponse.BodyHandlers.ofString()));
|
||||
}
|
||||
|
||||
public JsonObject post(String endpoint, JsonObject payload) throws IOException, InterruptedException {
|
||||
return postElement(endpoint, payload).getAsJsonObject();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user