How to delete a default command ? I'm using that but commands which aren't modified always work... PHP: $unregister = array("help", "version", "teleport", "give");foreach($unregister as $cmd){ if($this->getServer()->getCommandMap()->getCommand($cmd) !== null){ $this->getServer()->getCommandMap()->getCommand($cmd)->setLabel($cmd.'__'); $this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap()); }}$this->getServer()->getCommandMap()->register("help", new HelpCommand($this));$this->getServer()->getCommandMap()->register("version", new VersionCommand($this));$this->getServer()->getCommandMap()->register("teleport", new TeleportCommand($this)); Here, the command "give" will be always work while I have unregister the command... Is there a PM function to completely remove a default command ? The "unregister" function should not do this ?
I don't think you can remove a command. But you can overwrite it with a command that won't do anything.
If I want to remove all the defaults commands, it can be long... And, the unregister function remove also the alias of defaults commands ? For example, if I unregister /tell and I "overwrite it with a command that won't do anything", I must also unregister and "overwrite it with a command that won't do anything" for all the alias of /tell ?
It won't be long. And since the code is executed on plugin enable, it won't cause lag or reduce performance. PHP: $unregister = ["help", "version", "teleport", "give"];foreach($unregister as $cmd){ if($this->getServer()->getCommandMap()->getCommand($cmd) !== null){ $this->getServer()->getCommandMap()->getCommand($cmd)->setLabel($cmd.'__'); $this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap()); $this->getServer()->getCommandMap()->register($cmd, new UselessCommand($this)); }}
Try this if ever you'd like a command that does nothing when executed (this case it's help) PHP: public function onCommandPreProcess(PlayerCommandPreprocessEvent $event){ $args = explode(" ", $event->getMessage());if($args[0] == "/help"){ if (!($event->getPlayer() instanceof Player)){ return true;} else {$event->setCancelled();} PS : France un jour, France toujours !
Use English in thsi forhms please, so others can understand what you posted when reading thsi thread to get further information
Still, /help command does not send a message using this code, it may be hacky but It works. Et oui je suis français
Non ça marche pas tout le temps, j'utilisais cette manière et j'ai changé car elle marchait 1/5... Si tu ne me crois pas, regarde les discussions pocketmine ou shoghicp (le créateur de PocketMine) l'explique.
Speak English or speak in PM, and for me it works every time, maybe cause I'm using a fork, idk I'll test something else
I hate that still have to hack your way through the command map. And aliases are often still stuck somewhere in there.
Of course, but this should get a 'fix'. The cmd map is a true mess. And aliases look like they have been an afterthought.