Skip to content

Commit

Permalink
GH-1382 Fix username update (Fix #1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
crejk committed Jan 22, 2021
1 parent e8711a9 commit 3aa8231
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Expand Up @@ -57,6 +57,15 @@ public static void removeUser(User user) {
BY_NAME_USER_COLLECTION.remove(user.getName());
}

public static void updateUsername(User user, String newUsername) {
Validate.notNull(user, "user can't be null!");

BY_NAME_USER_COLLECTION.remove(user.getName());
BY_NAME_USER_COLLECTION.put(newUsername, user);

user.setName(newUsername);
}

public static boolean playedBefore(String nickname) {
return playedBefore(nickname, false);
}
Expand Down
Expand Up @@ -6,6 +6,7 @@
import net.dzikoysk.funnyguilds.basic.guild.RegionUtils;
import net.dzikoysk.funnyguilds.basic.user.User;
import net.dzikoysk.funnyguilds.basic.user.UserCache;
import net.dzikoysk.funnyguilds.basic.user.UserUtils;
import net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager;
import net.dzikoysk.funnyguilds.concurrency.requests.dummy.DummyGlobalUpdateUserRequest;
import net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer;
Expand Down Expand Up @@ -38,8 +39,10 @@ public void onJoin(PlayerJoinEvent e) {
user = User.create(player);
}
else {
if (! user.getName().equals(player.getName())) {
user.setName(player.getName());
String playerName = player.getName();

if (! user.getName().equals(playerName)) {
UserUtils.updateUsername(user, playerName);
}
}

Expand Down

0 comments on commit 3aa8231

Please sign in to comment.