Skip to content

Commit

Permalink
Merge pull request #77 from KingsMMA/master
Browse files Browse the repository at this point in the history
Use firstOrNull in NameCacheService to not throw for uncached players
  • Loading branch information
stephendotgg authored Dec 16, 2024
2 parents bd5a3a1 + 935a6b9 commit dfcaf7c
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ object NameCacheService {

private fun queryMongoNameByUUID(uuid: UUID): String? {
mongoCache.let {
mongoCache.find(Filters.eq("_id", uuid.toString())).first()
.let {
mongoCache.find(Filters.eq("_id", uuid.toString())).firstOrNull()
?.let {
val name =
it.getString("name") ?: throw MongoException("Document with '_id' '$uuid' has no field 'name'.")
cache[uuid] = name
return name
}
}
return null
}

private fun queryMojangNameByUUID(uuid: UUID): String {
Expand Down Expand Up @@ -78,13 +79,14 @@ object NameCacheService {
"name",
Pattern.compile("^$name$", Pattern.CASE_INSENSITIVE)
)
).first().let {
).firstOrNull()?.let {
val uuid = UUID.fromString(it.getString("_id"))
?: throw MongoException("Document with 'name' '$name' has no valid UUID at '_id'.")
cache[uuid] = name
return uuid
}
}
return null
}

private fun queryMojangUUIDByName(name: String): UUID {
Expand Down

0 comments on commit dfcaf7c

Please sign in to comment.