1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Sending a no permission message

Discussion in 'Development' started by rektpixel, Oct 9, 2017.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    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:
    <?php
    namespace 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 $senderCommand $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(-2653, -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
     
  2. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    I prefer you use this way:

    PHP:
    // inside of function onCommand bracket
    if(!$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.
     
    iiFlamiinBlaze likes this.
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    oh I understand, I think. I'll try it out thanks
     
  4. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    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.
     
  5. Rysieku

    Rysieku Spider Jockey

    Messages:
    34
    GitHub:
    rysieku
    How your plugin.yml looks like?
     
  6. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    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
    
     
  7. Rysieku

    Rysieku Spider Jockey

    Messages:
    34
    GitHub:
    rysieku
    Delete "permission: bcastle.use"
     
  8. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    worked :)
     
  9. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    What's the point sending the permission message when you already send a message saying you need this to use it.
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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.
     
    Kenn Fatt and rektpixel like this.
  11. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    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
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    HimbeersaftLP and Muqsit like this.
  13. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
  14. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    Oh new API? i didn't know about it before
     
  15. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    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.
     
    HimbeersaftLP likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.