Cleanup
This commit is contained in:
@@ -48,9 +48,9 @@ public class CitrusDevClient implements ClientModInitializer {
|
||||
while (openScreenKey.consumeClick()) {
|
||||
if (client.player != null && client.player.isShiftKeyDown()) {
|
||||
String lastModule = Config.get().lastModule;
|
||||
client.setScreen(new MyScreen(lastModule)); // sneak + RShift: last module
|
||||
client.setScreen(new MyScreen(lastModule));
|
||||
} else {
|
||||
client.setScreen(new MyScreen(null)); // RShift alone: general tab
|
||||
client.setScreen(new MyScreen(null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
// PLACE THIS FILE AT:
|
||||
// src/client/java/de/fullrisk/citrusDev/client/PlaytimeTracker.java
|
||||
//
|
||||
// NOT under src/main/java — MinecraftClient and client.player only exist
|
||||
// on the client source set. That is the actual cause of the
|
||||
// "Cannot resolve symbol" errors, not a mistake in this code.
|
||||
|
||||
package de.fullrisk.citrusDev.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -19,15 +12,9 @@ import com.google.gson.JsonParser;
|
||||
|
||||
public class PlaytimeTracker {
|
||||
|
||||
//ticks zu backend schicken
|
||||
private static final String BACKEND_URL = "http://62.116.42.223:25501/api/heartbeat";
|
||||
|
||||
private static final String BACKEND_URL =
|
||||
"http://62.116.42.223:25501/api/heartbeat";
|
||||
|
||||
private static final HttpClient HTTP =
|
||||
HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(10))
|
||||
.build();
|
||||
private static final HttpClient HTTP = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
|
||||
|
||||
private static int ticks = 0;
|
||||
private static int currentPlaytimeSeconds = 0;
|
||||
@@ -42,16 +29,14 @@ public class PlaytimeTracker {
|
||||
if (ticks >= 60) {
|
||||
ticks = 0;
|
||||
sendHeartbeat();
|
||||
getPlaytime(); // <-- add this
|
||||
|
||||
getPlaytime();
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendHeartbeat() {
|
||||
Verifier.sendTokenForVerification();
|
||||
|
||||
Minecraft client =
|
||||
Minecraft.getInstance();
|
||||
|
||||
Minecraft client = Minecraft.getInstance();
|
||||
|
||||
if (client.player == null) {
|
||||
System.out.println("No player yet");
|
||||
@@ -86,15 +71,9 @@ public class PlaytimeTracker {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//playtime vom server holen
|
||||
|
||||
private static final String PLAYTIME_URL =
|
||||
"http://62.116.42.223:25501/api/player/%s/playtime";
|
||||
|
||||
private static final String PLAYTIME_URL = "http://62.116.42.223:25501/api/player/%s/playtime";
|
||||
|
||||
public static void getPlaytime() {
|
||||
|
||||
Minecraft client = Minecraft.getInstance();
|
||||
|
||||
if (client.player == null) {
|
||||
@@ -103,57 +82,24 @@ public class PlaytimeTracker {
|
||||
|
||||
UUID uuid = client.player.getUUID();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(
|
||||
PLAYTIME_URL.formatted(uuid)
|
||||
))
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(PLAYTIME_URL.formatted(uuid)))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
|
||||
HTTP.sendAsync(
|
||||
request,
|
||||
HttpResponse.BodyHandlers.ofString()
|
||||
)
|
||||
HTTP.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||
.thenAccept(response -> {
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
|
||||
String json = response.body();
|
||||
|
||||
JsonObject data =
|
||||
JsonParser.parseString(json)
|
||||
.getAsJsonObject();
|
||||
JsonObject data = JsonParser.parseString(json).getAsJsonObject();
|
||||
|
||||
|
||||
currentPlaytimeSeconds =
|
||||
data.get("playtime_seconds")
|
||||
.getAsInt();
|
||||
|
||||
|
||||
// Compare playtime here
|
||||
if (currentPlaytimeSeconds >= 3600) {
|
||||
System.out.println(
|
||||
"Player has more than 1 hour!"
|
||||
);
|
||||
}
|
||||
else {
|
||||
System.out.println(
|
||||
"Player needs more time"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
System.out.println(
|
||||
"Seconds played: " + currentPlaytimeSeconds
|
||||
);
|
||||
currentPlaytimeSeconds = data.get("playtime_seconds").getAsInt();
|
||||
|
||||
} else {
|
||||
System.out.println(
|
||||
"Failed: " + response.statusCode()
|
||||
);
|
||||
System.err.println("Failed: " + response.statusCode());
|
||||
throw new RuntimeException("Failed to get playtime: " + response.statusCode());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@ public class Verifier {
|
||||
|
||||
private static final String VERIFY_URL = "http://62.116.42.223:25501/api/verify";
|
||||
|
||||
private static final HttpClient HTTP = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(10))
|
||||
.build();
|
||||
private static final HttpClient HTTP = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
|
||||
|
||||
public static void sendTokenForVerification() {
|
||||
String accessToken = Authentication.getAccessToken();
|
||||
|
||||
Reference in New Issue
Block a user