From 50d4b2df8690932558143e4bfafb1b7a57af41ec Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 10 Apr 2024 10:36:31 +0100 Subject: [PATCH] add more logging to the PlayerService and ServerService --- .../java/cc.fascinated/service/PlayerService.java | 11 ++++++----- .../java/cc.fascinated/service/ServerService.java | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/cc.fascinated/service/PlayerService.java b/src/main/java/cc.fascinated/service/PlayerService.java index 11d2ce6..4bc23e4 100644 --- a/src/main/java/cc.fascinated/service/PlayerService.java +++ b/src/main/java/cc.fascinated/service/PlayerService.java @@ -43,23 +43,24 @@ public class PlayerService { * @return the player */ public CachedPlayer getPlayer(String id) { + String originalId = id; id = id.toUpperCase(); // Convert the id to uppercase to prevent case sensitivity - log.info("Getting player: {}", id); - UUID uuid = PlayerUtils.getUuidFromString(id); + log.info("Getting player: {}", originalId); + UUID uuid = PlayerUtils.getUuidFromString(originalId); if (uuid == null) { // If the id is not a valid uuid, get the uuid from the username uuid = usernameToUuid(id); } Optional cachedPlayer = playerCacheRepository.findById(uuid); if (cachedPlayer.isPresent()) { // Return the cached player if it exists - log.info("Player {} is cached", id); + log.info("Player {} is cached", originalId); return cachedPlayer.get(); } try { - log.info("Getting player profile from Mojang: {}", id); + log.info("Getting player profile from Mojang: {}", originalId); MojangProfile mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang - log.info("Got player profile from Mojang: {}", id); + log.info("Got player profile from Mojang: {}", originalId); Tuple skinAndCape = mojangProfile.getSkinAndCape(); CachedPlayer player = new CachedPlayer( uuid, // Player UUID diff --git a/src/main/java/cc.fascinated/service/ServerService.java b/src/main/java/cc.fascinated/service/ServerService.java index eb48f20..f0898e8 100644 --- a/src/main/java/cc.fascinated/service/ServerService.java +++ b/src/main/java/cc.fascinated/service/ServerService.java @@ -36,14 +36,17 @@ public class ServerService { * @return the server */ public CachedMinecraftServer getServer(String platformName, String hostname, int port) { + log.info("Getting server: {} {}:{}", platformName, hostname, port); MinecraftServer.Platform platform = EnumUtils.getEnumConstant(MinecraftServer.Platform.class, platformName.toUpperCase()); if (platform == null) { + log.info("Invalid platform: {} for server {}:{}", platformName, hostname, port); throw new BadRequestException("Invalid platform: %s".formatted(platformName)); } String key = "%s-%s:%s".formatted(platformName, hostname, port); Optional cached = serverCacheRepository.findById(key); if (cached.isPresent()) { + log.info("Server {}:{} is cached", hostname, port); return cached.get(); } @@ -58,6 +61,7 @@ public class ServerService { platform.getPinger().ping(hostname, port), System.currentTimeMillis() ); + log.info("Found server: {}:{}", hostname, port); serverCacheRepository.save(server); server.setCached(-1); // Indicate that the server is not cached return server;