Make the taken username check more accurate (#336)

Instead of using `Bukkit.getPlayer(name)`, now each player is manually iterated over to check if a username is taken. This fixes multiple problems, such as a player not being able to set their name to `a` because a player named `ab` is online, and a player not being able to set their username back to the one they joined with.
This commit is contained in:
Chipmunk 2023-02-06 01:10:41 +00:00 committed by GitHub
parent f6f5ae6efb
commit 820b105327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -55,7 +55,9 @@ public final class CommandUsername implements CommandExecutor {
return true;
}
if (Bukkit.getPlayer(name) != null) {
for (Player other : Bukkit.getOnlinePlayers()) {
if (!other.getName().equals(name)) continue;
player.sendMessage(Component
.text("A player with that username is already logged in."));
return true;