I'm a little bit puzzled atm with some code I posted a few days ago with a different question regarding it I have this: PHP: <?phpnamespace itsmemes\ipe;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\plugin\Plugin;use pocketmine\Server;use pocketmine\Player;use pocketmine\math\Vector3;class Main extends PluginBase implements Listener{ private $config; public function onCommand(CommandSender $sender, Command $command, $label, array $args) : bool{ switch ($command->getName()) { case "bcastle": if($sender->hasPermission("bcastle.use")) { $sender->sendMessage("§e[NPC] §7: §eManager§7: §fHave fun bouncing!"); $sender->teleport(new \pocketmine\math\Vector3(-26, 53, -863)); return true; }else{ $sender->sendMessage("§e[NPC] §7: §eManager§7: §fI can't let you on the bouncy castle! You don't have VIP or MVP rank! Buy a rank at: Store.#Blanked#.net"); return true; } } }} This all works apart from if the player doesn't have to permission bcastle.use it gives them the default PocketMine error message, I want it to send what is after }else{ but It seems I have not done this correctly? I looked at what others have done and it looks similar so yeah I'm a bit confused but probably a really easy fix. thanks
I prefer you use this way: PHP: // inside of function onCommand bracketif(!$sender->hasPermission("bcastle.use")) { $sender->sendMessage("No permission to use this command!"); return false;}// your another code should be here...return true; Since new API, onCommand should be returned as boolean. And with that way, you has 2 condition (false and true) if you still miss understanding, feel free to ask or mention me.
Oh this did the opposite, sends the pocketmine no permission message when the player has the permission. and when the player does not have permission it works. Which looks obvious now.
Code: name: Bouncy author: itsmemes main: itsmemes\ipe\Main version: 0.0.1 api: 3.0.0-ALPHA9 load: STARTUP commands: bcastle: description: "Go into the bouncy castle" permission: bcastle.use permissions: bcastle.use: description: "Allows the user to run the bcastle command" default: OP
What's the point sending the permission message when you already send a message saying you need this to use it.
This might work too PHP: //Plugin::onEnable()$this->getServer()->getCommandMap()->getCommand("yourcmd")->setPermissionMessage("You don't have permission boi"); That way, you can modify default command's permission message too.
No the problem was is that the no permission message wasn't sending but I just had something wrong in the plugin.yml, its fixed now
The plugin.yml was not wrong. The reason you had this issue is because of the order a default PluginCommand executes. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/command/PluginCommand.php#L54
oh but it did work when I deleted 'permission: bcastle.usepermission: bcastle.use' from the plugin.yml
It's not new. It's been around for a LONG time for plugin commands, but is mostly unused by new developers. When a command is created within a plugin's plugin.yml file, a PluginCommand instance is created for the command. When onCommand is used through the PluginBase, the PluginCommand instance calls to the function because it is the default set executor of the command. However, before the executor is called, the permissions are tested, so this error occured.