Has anything changed recently with the minimum player name length? I probably need to look through the PMMP code to see if there is anything enforcing it there. I've been noticing just the last few days players have been using one character and two character player names. Is this something that was checked by the MCPE app before, and changed with 1.0.6? Sorry if I'm missing something obvious.
Ah, it looks like PMMP used to verify that username was 3 characters or more; but at some point it stopped. Probably this wasn't recent. I assume this is intended? Code in Player.php from a few months ago: PHP: $valid = true; $len = strlen($packet->username); if($len > 16 or $len < 3){ $valid = false; } for($i = 0; $i < $len and $valid; ++$i){ $c = ord($packet->username{$i}); if(($c >= ord("a") and $c <= ord("z")) or ($c >= ord("A") and $c <= ord("Z")) or ($c >= ord("0") and $c <= ord("9")) or $c === ord("_") ){ continue; } $valid = false; break; } Now replaced with: PHP: public static function isValidUserName(string $name) : bool{ $lname = strtolower($name); $len = strlen($name); return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("/[^A-Za-z0-9_]/", $name) === 0; }
Yeah, I already modified my server to force 3; as I think that's just better. But I didn't want to make a PR because maybe I'm the only one that thinks this Since it's a single character edit to the code; I'm sure if a lot of people comment in this thread someone will make the change eventually. So far it doesn't seem to be such a big deal to most people.
PHP: public function onJoin() { if(strlen($player) < 3) { $server->sendMessage("kick " . $player . " Your name needs to be at least 3 letters long!"); }}
If that is supposed to be working code, that's not correct. Every variable is undefined, the event handler is incorrect, and ServerObject->sendMessage() isn't an existing method, as far as I know. I do think you are correct that a plugin could be used to check for a proper length name though.
PHP: public function onPreLogin(PlayerPreLoginEvent $event) { $player = $event->getPlayer(); if(strlen($player) < 3) { $cmd = "kick " . $player . " Your name needs to be at least 3 letters long!"; $this->getServer()->dispatchCommand(new ConsoleCommandSender(),$cmd); }} Old PocketMine Forums: I don't know how to do that.
Um, does my code look good? Or silly beginner mistakes...? I tried my own code and it didn't work. No idea what the problem could be.
PHP: public function onPreLogin(PlayerPreLoginEvent $event) { $player = $event->getPlayer(); if(strlen($player->getName()) < 3) { //function parameter must be string, not player object $event->setCancelled(); // set event to cancelled for other plugins and to prevent errors $event->setKickMessage("Your name needs to be at least 3 letters long!"); // added message for player to see on their logout }}