Server: rename getPlayer() to getPlayerByPrefix()

closes #3910

the existing naming was misleading, and many plugin devs assumed that it returns an exact match. However, this is not guaranteed, and it's possible for two different players to match the same prefix.

- There is no defined behaviour for what happens when multiple players can equally match a prefix (e.g. 'fr' could match 'fred' or 'frog' equally, because the name lengths are the same)
- A prefix might match a different player at a different time (e.g. 'fr' could match 'freddie' before 'fred' joins, after which it will match 'fred' instead)

With these flaws in mind, it's better to break compatibility on this to make the intent more clear, and to make plugin developers reassess their usages of this method. In most non-command use cases, they should likely be using getPlayerExact() instead.
This commit is contained in:
Dylan K. Taylor
2020-11-14 15:49:41 +00:00
parent 41a8007c47
commit 7469f28f24
13 changed files with 14 additions and 12 deletions

View File

@ -48,7 +48,7 @@ class TeleportCommand extends VanillaCommand{
}
private function findPlayer(CommandSender $sender, string $playerName) : ?Player{
$subject = $sender->getServer()->getPlayer($playerName);
$subject = $sender->getServer()->getPlayerByPrefix($playerName);
if($subject === null){
$sender->sendMessage(TextFormat::RED . "Can't find player " . $playerName);
return null;