From abaa9b376f1d28edb534a0190800d0ba2d16568c Mon Sep 17 00:00:00 2001 From: EmmaKnijn <64010592+EmmaKnijn@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:39:53 +0200 Subject: [PATCH] add player amount information --- src/main/java/ct/server/Ctserver.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/ct/server/Ctserver.java b/src/main/java/ct/server/Ctserver.java index 22eb496..e509b55 100644 --- a/src/main/java/ct/server/Ctserver.java +++ b/src/main/java/ct/server/Ctserver.java @@ -38,17 +38,18 @@ public class Ctserver implements ModInitializer { } }); } - private void sendPostRequest(String urlString, String plaintext) throws Exception { + private void sendPostRequest(String urlString, String tps, String playerCount) throws Exception { URL url = new URL(urlString); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "text/plain; utf-8"); - con.setRequestProperty("TPS", plaintext); + con.setRequestProperty("TPS", tps); + con.setRequestProperty("PLAYERCOUNT", playerCount); con.setRequestProperty("Accept", "text/plain"); con.setDoOutput(true); try (OutputStream os = con.getOutputStream()) { - byte[] input = plaintext.getBytes(StandardCharsets.UTF_8); + byte[] input = tps.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } @@ -61,7 +62,8 @@ public class Ctserver implements ModInitializer { tickCounter++; if (tickCounter >= 20) { - + int playerCount = minecraftServer.getCurrentPlayerCount(); + LOGGER.info(String.valueOf(playerCount)); double afterTicks = Instant.now().toEpochMilli(); double timeBetween = afterTicks - zeroTicks; double mspt = (timeBetween / 20) ; @@ -72,7 +74,7 @@ public class Ctserver implements ModInitializer { if (tps <= 20) { CompletableFuture.runAsync(() -> { try { - sendPostRequest("http://us-ky-medium-0004.knijn.one:58926/tps", String.valueOf(tps)); + sendPostRequest("http://us-ky-medium-0004.knijn.one:58926/tps", String.valueOf(tps),String.valueOf(playerCount)); } catch (Exception e) { LOGGER.error("Failed to send POST request", e); }