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
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:
parent
50ae9b47be
commit
50d4b2df86
@ -43,23 +43,24 @@ public class PlayerService {
|
|||||||
* @return the player
|
* @return the player
|
||||||
*/
|
*/
|
||||||
public CachedPlayer getPlayer(String id) {
|
public CachedPlayer getPlayer(String id) {
|
||||||
|
String originalId = id;
|
||||||
id = id.toUpperCase(); // Convert the id to uppercase to prevent case sensitivity
|
id = id.toUpperCase(); // Convert the id to uppercase to prevent case sensitivity
|
||||||
log.info("Getting player: {}", id);
|
log.info("Getting player: {}", originalId);
|
||||||
UUID uuid = PlayerUtils.getUuidFromString(id);
|
UUID uuid = PlayerUtils.getUuidFromString(originalId);
|
||||||
if (uuid == null) { // If the id is not a valid uuid, get the uuid from the username
|
if (uuid == null) { // If the id is not a valid uuid, get the uuid from the username
|
||||||
uuid = usernameToUuid(id);
|
uuid = usernameToUuid(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
||||||
if (cachedPlayer.isPresent()) { // Return the cached player if it exists
|
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();
|
return cachedPlayer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
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();
|
Tuple<Skin, Cape> skinAndCape = mojangProfile.getSkinAndCape();
|
||||||
CachedPlayer player = new CachedPlayer(
|
CachedPlayer player = new CachedPlayer(
|
||||||
uuid, // Player UUID
|
uuid, // Player UUID
|
||||||
|
@ -36,14 +36,17 @@ public class ServerService {
|
|||||||
* @return the server
|
* @return the server
|
||||||
*/
|
*/
|
||||||
public CachedMinecraftServer getServer(String platformName, String hostname, int port) {
|
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());
|
MinecraftServer.Platform platform = EnumUtils.getEnumConstant(MinecraftServer.Platform.class, platformName.toUpperCase());
|
||||||
if (platform == null) {
|
if (platform == null) {
|
||||||
|
log.info("Invalid platform: {} for server {}:{}", platformName, hostname, port);
|
||||||
throw new BadRequestException("Invalid platform: %s".formatted(platformName));
|
throw new BadRequestException("Invalid platform: %s".formatted(platformName));
|
||||||
}
|
}
|
||||||
String key = "%s-%s:%s".formatted(platformName, hostname, port);
|
String key = "%s-%s:%s".formatted(platformName, hostname, port);
|
||||||
|
|
||||||
Optional<CachedMinecraftServer> cached = serverCacheRepository.findById(key);
|
Optional<CachedMinecraftServer> cached = serverCacheRepository.findById(key);
|
||||||
if (cached.isPresent()) {
|
if (cached.isPresent()) {
|
||||||
|
log.info("Server {}:{} is cached", hostname, port);
|
||||||
return cached.get();
|
return cached.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +61,7 @@ public class ServerService {
|
|||||||
platform.getPinger().ping(hostname, port),
|
platform.getPinger().ping(hostname, port),
|
||||||
System.currentTimeMillis()
|
System.currentTimeMillis()
|
||||||
);
|
);
|
||||||
|
log.info("Found server: {}:{}", hostname, port);
|
||||||
serverCacheRepository.save(server);
|
serverCacheRepository.save(server);
|
||||||
server.setCached(-1); // Indicate that the server is not cached
|
server.setCached(-1); // Indicate that the server is not cached
|
||||||
return server;
|
return server;
|
||||||
|
Loading…
Reference in New Issue
Block a user