PHP: public function onJoin(PlayerJoinEvent $e){$player = $e->getPlayer();if($player->getName() == "dumbass"){$player->close("", "bad name");}} I want to block users with bad usernames but they can bypass it by just adding one capital word or removing one
strtolower it. Don't trust caps. And you could create an array with known usernames from a specific player and then see if it's alike to it.
To check if they have any amount of capitals in their name: PHP: public function onJoin(PlayerJoinEvent $e){$player = $e->getPlayer();if($player->getName() !== "dumbass"){ // they have caps$player->close("", "bad name");} This is a very simple example. Provided you have the bad name lowercase, checking the player name against it (player: "dumBass", bad name: "dumbass) will work without the use of strtolower
will PHP: public function onJoin(PlayerJoinEvent $e){$player = $e->getPlayer();if($player->getName() !== "dumbass"){ // they have caps$player->close("", "bad name");} kick players even with caps in "dumbass"?
if you don't understand what hes trying say just use this PHP: if(strtolower($player->getName()) == "dumbass"){ you don't have to use this example ;-;
Idk if this would help, but this plugin does exactly what you desire. https://imgcl.co/plugins/badnames.782/ could use it as a reference.
it worked perfectly but I get error CODE: PHP: <?phpnamespace KD;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerLoginEvent;use pocketmine\utils\Config;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->saveDefaultConfig(); } public function onJoin(PlayerLoginEvent $e){$player = $e->getPlayer(); if(strtolower($player->getName()) == "dumbass"){$player->close("", "bad name!"); } }} ERROR: Code: 01:06:04 [INFO] DumBaSs[/x.1x.x.7x:53xx8] logged out due to bad name 01:06:04 [CRITICAL] Error: "Call to a member function sendTime() on null" (EXCEPTION) in "/src/pocketmine/Player" at line 2142
Just a tip, replace the event with PlayerPreLoginEvent. If you kick the player on PlayerJoinEvent, the player has already requested for chunks and the server has already done pointless calculations. Save on performance.
Oh yeah. Call PlayerPreLoginEvent::setLeaveMessage("bad name!") instead of kicking the player. Then cancel the event.
final product? PHP: public function prelogin(PlayerPreLoginEvent $ev){if($ev->getPlayer()->getName() !== "dumbass"){return true;}$ev->setCancelled(true);$ev->setLeaveMessage("bad name");}
Two tips: - use stripos to make sure the text is included, in case their username is something like: "_dumbass_". - use Regex to replace all characters between letters, in case their username is something like: "dumb_ass".