Hey, I want to do command with a ! because i think this is more cool as /. Now How to see if player has do the good command The command is like that !ban {player}. I know use PlayerChatevent. and i know how to get the message but how to know if player has do the correct usage? thanks! And sorry i'm french
You could get the message from PlayerChatEvent, and use $args = explode(" ", $message); Be careful with $args[0], because $args[0] would be the actual command, not the first argument. To check if the first symbol is the one you want it to be, use: if($message[0] === "!") { } I hope that helps.
Okay, $message[0] you mean $args[0]? because i have see the function explode And they just coold be $args[0] But $args[0] can't contain only ! because you said explode " " So $args[0] contain "!ban" and $args[1] contain the name. I think you mean that if i'm false Tell me please
PHP: /** @var PlayerCommandPreprocessEvent $event */$message = $event->getMessage();if($message[0] === "!"){ $expl = explode(" ", $message); $command = substr($expl[0], 1); $expl[0] = "/".$command; $event->setMessage(implode(" ", $expl));}
PHP: public function specialCommand (PlayerCommandPreprocessEvent $event) { $message = $event->getMessage(); if($message[0] == "!") { $msgParts = explode(" ", $message); //separate the message by the spaces $command = substr($msgParts[0], 1); //extract command $msgParts[0] = "/".$command; //change the ! into a / $event->setMessage(implode(" ", $msgParts)); //set message to be a proper command for processing }}
Without using the hacky string as an array and risk throwing errors method: PHP: public function onPlayerCommandPreprocess(pocketmine\event\player\PlayerCommandPreprocessEvent $event) { $message = $event->getMessage(); if(substr($message, 0, 1) === "!") { $message = trim($message, "!"); $event->setMessage("/" . $message); }}
English? The command hasn't been processed yet, hence the event name being 'player command preprocess event'.
Note: These will cause the loss of client prediction (and usage display when PocketMine supports them in API 3.0.0) of commands. Only commands starting with / can be understood by MCPE as commands. Commands not starting with / will cause worse player experience and inconvenience.
Also, please, be independent. Don't use ! commands just because other people do it too -- it's not a symbol of being special; it's a symbol of following the trends passively. Be yourself! This is nothing cool at all if everyone does this.
That's sort of hypocritical because you are saying for everyone to be like each other and use the default /
Maybe you are right, but at least it's more sensible to use the slash than blindly following the trend of using the other symbols, which will only make user experience worse, especially for people who don't know how to do that but just "I wan tis too cuz they have it on their server nd their cool cummon steel the plugon for meee". There isn't even a valid reason to introduce such change.
On the other hand, of course it's reasonable if you want to reroute command starting with the fullwidth (Unicode) form of slash: Code: /
Yep, it's the same with custom enchants, one server has them and now everyone wants that, even tough it's so useless....