i want 2 make login but i want to kick players if they failed putting password 5 times PHP: public function onBreakBreakEvent(BlockBreakEvent $event){ $player= $event->getPlayer()->getName(); if(isset($this->login[$player])){ $event->setCancelled(true); $event->getPlayer()->sendMessage("Please login first!"); } }
You've to store some kind of counter per player and increment that counter every time a player attempts to log in. Implementation is left as an exercise to the reader.
Try something like this PHP: /** @var Player $p */if(!isset($this->attempt[strotlower($p->getName()])){ $this->attempt[strtolower($p->getName())] = 1; return;}$this->attempt[strtolower($p->getName())] += 1;if($this->attempt[strtolower($p->getName())] == 5){ $p->kick('You reached max password attempts');}
for these who plan to copy said code: please do not hardcode say "magic number" using something like a const would be better using a config would be prefered
Why? Just stating what you think to be a good idea without reason is pretty sketchy. Whilst what you said is a good idea and should be used in these situations, you should provide some evidence as to why it should be done. Giving out advice like this and just assuming people know or understand why it is considered good practice to do so doesn't really help advance the knowledge of those reading and is comparable to just spewing out code on demand. For those actually wondering why you should use a config or constant to store the value: It allows you or the users of the plugin to easily modify and view the value instead of having to search for every occurrence in the code. This improves the readability of the code and also makes maintenance easier.
It looks like the code you posted is completely irrelevant to your question. Did I misunderstand you?