Skip to content

Commit

Permalink
Retrieve members even if they are not cached
Browse files Browse the repository at this point in the history
  • Loading branch information
Chickenpowerrr committed Jul 8, 2021
1 parent a023870 commit 132078f
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,31 @@ static PlayerFactory getInstance(Guild guild) {
*/
@Override
public CompletableFuture<Void> setUuid(String playerId, UUID uuid) {
return getPlayer(this.guild.getMemberById(playerId)).thenAccept(player -> {
if (uuid == null) {
this.players.remove(player.getUuid());
player.setUuid(null);
} else {
this.players.remove(player.getUuid());
this.players.put(uuid, player);
player.setUuid(uuid);
}
CompletableFuture<Void> result = new CompletableFuture<>();

this.guild.retrieveMemberById(playerId).submit().thenAccept(member -> {
getPlayer(member).thenAccept(player -> {
if (uuid == null) {
this.players.remove(player.getUuid());
player.setUuid(null);
} else {
this.players.remove(player.getUuid());
this.players.put(uuid, player);
player.setUuid(uuid);
}
result.complete(null);
}).exceptionally(throwable -> {
throwable.printStackTrace();
result.completeExceptionally(throwable);
return null;
});
}).exceptionally(throwable -> {
throwable.printStackTrace();
result.completeExceptionally(throwable);
return null;
});

return result;
}

/**
Expand Down Expand Up @@ -122,7 +134,8 @@ public CompletableFuture<Player> getPlayer(UUID uuid) {
return this.bot.getEffectiveDatabase()
.getPlayer(uuid, (uuid1, identifier, timesSynced, timesUnsynced) -> {
if (identifier != null) {
Member member = this.guild.getMemberById(identifier);
Member member = this.guild.retrieveMemberById(identifier)
.onErrorMap(throwable -> null).complete();
if (member != null) {
return new com.gmail.chickenpowerrr.ranksync.discord.player.Player(uuid,
member, this.bot, timesSynced, timesUnsynced);
Expand Down

0 comments on commit 132078f

Please sign in to comment.