Player "a" doesn't have "pocketmine.command.give" I want to "a" can use /give command. So, I make plugin. PHP: public function onCommandProcessEvent(PlayerCommandPreprocessEvent $ev) { $player = $ev->getPlayer(); $msg = $ev->getMessage(); $words = explode(" ", $msg); $cmd = strtolower(substr(array_shift($words), 1)); if ($cmd === "give") { $this->getServer()->dispatchCommand($player, $msg); } } Is this right?
What originally happens: 1. Player sends the command 2. PocketMine fires PlayerCommandPreprocessEvent 3. If event is not cancelled, PocketMine executes the command. What happens with your plugin added: 1. Player sends the command 2. PocketMine fires PlayerCommandPreprocessEvent 2.a) Your plugin finds that the command is /give 2.b) Your plugin calls dispatchComman() with /give 3. The event is not cancelled, so PocketMine executes the command again. If you simply want to add a permission to the player, you may use permission attachments. Here is a basic example for managing permissions: https://github.com/SOF3/simple-plug...lePermissions/SimplePermissions.php#L173-L203 https://github.com/SOF3/simple-plug.../SimplePermissions/SimplePermissions.php#L135 https://github.com/SOF3/simple-plug.../SimplePermissions/SimplePermissions.php#L160 Also note that PlayerCommandPreprocessEvent is fired for all chat messages + commands sent to the player, so simply checking whether the command matches "?give *" doesn't guarantee that it is a command -- a chat message "ogive is a free-hand graph showing the curve of a cumulative distribution function" will also be executed as the command. In addition, $msg contains the leading slash, while dispatchCommand() parameter 2 does not require the leading slash (just like console commands).
I make plugin. PHP: public function onCommandProcessEvent(PlayerCommandPreprocessEvent $ev) { $player = $ev->getPlayer(); $msg = $ev->getMessage(); $words = explode(" ", $msg); $cmd = strtolower(substr(array_shift($words), 1)); if ($this->isCmd($cmd)) { if ($this->isPolice(strtolower($player->getName()))) { $ev->setCancelled(true); $message = substr($msg, 1); $per = $this->getServer()->getCommandMap()->getCommand($cmd)->getPermission(); $ev->getPlayer()->addAttachment($this)->setPermission($per, true); $name = $ev->getPlayer()->getName(); $this->getServer()->dispatchCommand($player, $message); $this->getServer()->getPlayerExact($name)->addAttachment($this)->setPermission($per, false); } } } } When I tested, command's usage doesn't appear. What is wrong? PHP: public function isCmd($command) { return $this->cmd->exists($command); }