fix username to uuid cache
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Has been cancelled
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Has been cancelled
This commit is contained in:
parent
bda70b19a8
commit
a966977d82
@ -14,18 +14,24 @@ import java.util.UUID;
|
|||||||
@ToString
|
@ToString
|
||||||
@RedisHash(value = "playerName", timeToLive = 60L * 60L * 6) // 6 hours (in seconds)
|
@RedisHash(value = "playerName", timeToLive = 60L * 60L * 6) // 6 hours (in seconds)
|
||||||
public final class CachedPlayerName extends CachedResponse {
|
public final class CachedPlayerName extends CachedResponse {
|
||||||
|
/**
|
||||||
|
* The id of the player.
|
||||||
|
*/
|
||||||
|
@Id private final String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The username of the player.
|
* The username of the player.
|
||||||
*/
|
*/
|
||||||
@Id private final String username;
|
private final String username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The unique id of the player.
|
* The unique id of the player.
|
||||||
*/
|
*/
|
||||||
private final UUID uniqueId;
|
private final UUID uniqueId;
|
||||||
|
|
||||||
public CachedPlayerName(String username, UUID uniqueId) {
|
public CachedPlayerName(String id, String username, UUID uniqueId) {
|
||||||
super(CacheInformation.defaultCache());
|
super(CacheInformation.defaultCache());
|
||||||
|
this.id = id;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,8 @@ public class PlayerService {
|
|||||||
*/
|
*/
|
||||||
public CachedPlayerName usernameToUuid(String username) {
|
public CachedPlayerName usernameToUuid(String username) {
|
||||||
log.info("Getting UUID from username: {}", username);
|
log.info("Getting UUID from username: {}", username);
|
||||||
Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(username.toUpperCase());
|
String id = username.toUpperCase();
|
||||||
|
Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(id);
|
||||||
if (cachedPlayerName.isPresent() && Config.INSTANCE.isProduction()) {
|
if (cachedPlayerName.isPresent() && Config.INSTANCE.isProduction()) {
|
||||||
return cachedPlayerName.get();
|
return cachedPlayerName.get();
|
||||||
}
|
}
|
||||||
@ -111,7 +112,7 @@ public class PlayerService {
|
|||||||
throw new ResourceNotFoundException("Player with username '%s' not found".formatted(username));
|
throw new ResourceNotFoundException("Player with username '%s' not found".formatted(username));
|
||||||
}
|
}
|
||||||
UUID uuid = UUIDUtils.addDashes(mojangUsernameToUuid.getUuid());
|
UUID uuid = UUIDUtils.addDashes(mojangUsernameToUuid.getUuid());
|
||||||
CachedPlayerName player = new CachedPlayerName(username, uuid);
|
CachedPlayerName player = new CachedPlayerName(id, username, uuid);
|
||||||
playerNameCacheRepository.save(player);
|
playerNameCacheRepository.save(player);
|
||||||
log.info("Got UUID from username: {} -> {}", username, uuid);
|
log.info("Got UUID from username: {} -> {}", username, uuid);
|
||||||
player.getCache().setCached(false);
|
player.getCache().setCached(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user