add more logging to the PlayerService and ServerService
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m24s

This commit is contained in:
Lee 2024-04-10 10:36:31 +01:00
parent 50ae9b47be
commit 50d4b2df86
2 changed files with 10 additions and 5 deletions

@ -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> 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<Skin, Cape> skinAndCape = mojangProfile.getSkinAndCape();
CachedPlayer player = new CachedPlayer(
uuid, // Player UUID

@ -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<CachedMinecraftServer> 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;