From 48fdd39e8b95f44023c34b9eb16ad5cfd4444294 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Mon, 25 Dec 2023 01:52:36 +0000 Subject: [PATCH] Add debug logs for success/fail --- .../core/services/AnalyticsService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java index 25a5a9f724..e24134f64d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java @@ -75,8 +75,12 @@ private void send(String id, double[] doubles, String[] blobs) { if (!enabled) return; JsonObject object = new JsonObject(); - object.addProperty("index", id); + // Up to 1 index + JsonArray indexes = new JsonArray(); + indexes.add(id); + object.add("indexes", indexes); + // Up to 20 doubles (including the version) JsonArray doublesArray = new JsonArray(); doublesArray.add(VERSION); if (doubles != null) { @@ -86,6 +90,7 @@ private void send(String id, double[] doubles, String[] blobs) { } object.add("doubles", doublesArray); + // Up to 20 blobs JsonArray blobsArray = new JsonArray(); if (blobs != null) { for (String s : blobs) { @@ -101,6 +106,14 @@ private void send(String id, double[] doubles, String[] blobs) { client.sendAsync(HttpRequest.newBuilder() .uri(URI.create(API_URL)) .POST(HttpRequest.BodyPublishers.ofString(object.toString())) - .build(), HttpResponse.BodyHandlers.discarding()); + .build(), + HttpResponse.BodyHandlers.discarding() + ).thenAcceptAsync((res) -> { + if (res.statusCode() == 200) { + Debug.log(TestCase.ANALYTICS, "Analytics data for " + id + " sent successfully"); + } else { + Debug.log(TestCase.ANALYTICS, "Analytics data for " + id + " failed to send - " + res.statusCode()); + } + }); } }