@@ -166,8 +166,23 @@ public User loadUncachedUser(final UUID uuid) {
166166 if (userFile .exists ()) {
167167 player = new OfflinePlayerStub (uuid , ess .getServer ());
168168 user = new User (player , ess );
169- ((OfflinePlayerStub ) player ).setName (user .getLastAccountName ());
170- uuidCache .updateCache (uuid , user .getLastAccountName ());
169+ final String accName = user .getLastAccountName ();
170+ ((OfflinePlayerStub ) player ).setName (accName );
171+ // Check to see if there is already a UUID mapping for the name in the name cache before updating it.
172+ // Since this code is ran for offline players, there's a chance we could be overriding the mapping
173+ // for a player who changed their name to an older player's name, let that be handled during join.
174+ //
175+ // Here is a senerio which could take place if didn't do the containsKey check;
176+ // "JRoyLULW" joins the server - "JRoyLULW" is mapped to 86f39a70-eda7-44a2-88f8-0ade4e1ec8c0
177+ // "JRoyLULW" changes their name to "mbax" - Nothing happens, they are yet to join the server
178+ // "mdcfe" changes their name to "JRoyLULW" - Nothing happens, they are yet to join the server
179+ // "JRoyLULW" (formally "mdcfe") joins the server - "JRoyLULW" is mapped to 62a6a4bb-a2b8-4796-bfe6-63067250990a
180+ // The /baltop command is ran, iterating over all players.
181+ //
182+ // During the baltop iteration, two uuids have the `last-account-name` of "JRoyLULW" creating the
183+ // potential that "JRoyLULW" is mapped back to 86f39a70-eda7-44a2-88f8-0ade4e1ec8c0 when the true
184+ // bearer of that name is now 62a6a4bb-a2b8-4796-bfe6-63067250990a.
185+ uuidCache .updateCache (uuid , (accName == null || uuidCache .getNameCache ().containsKey (accName )) ? null : accName );
171186 return user ;
172187 }
173188
0 commit comments