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

Permission not working

Discussion in 'Plugin Help' started by Adei, Oct 26, 2019.

  1. Adei

    Adei Silverfish

    Messages:
    20
    GitHub:
    Adwin
    uhh im trying to add permission to a nickui command but it doesnt seem to work help pls!

    function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{
    if($sender instanceof Player){
    if($command->getName() === "nick"){
    if($player->hasPermission)("nick.use")){
    $this->openNickUI($sender);
    }
    } return true;
    }
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Remove the ) after hasPermisson:
    if($player->hasPermission("nick.use")){
     
  3. Adei

    Adei Silverfish

    Messages:
    20
    GitHub:
    Adwin
    it doesnt work
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Also replace $player with $sender, because $player isn't defined anywhere.

    PHP:
    function onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{
      if(
    $command->getName() === "nick"){
        if(
    $sender instanceof Player){
          if(
    $sender->hasPermission("nick.use")){
            
    $this->openNickUI($sender);
          }
        }
      }
      return 
    true;
    }
     
  5. Adei

    Adei Silverfish

    Messages:
    20
    GitHub:
    Adwin
    aight ill look into it
     
  6. Adei

    Adei Silverfish

    Messages:
    20
    GitHub:
    Adwin
    it doesnt work heres the full php file the problem says its at line 96
    PHP:
    <?php

    namespace matze;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    jojoe77777\FormAPI;
    use 
    jojoe77777\FormAPI\SimpleForm;
    use 
    jojoe77777\FormAPI\CustomForm;
    use 
    pocketmine\utils\TextFormat as C;

    class 
    nickui extends PluginBase implements Listener{
        function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{
            if(
    $sender instanceof Player){
                if(
    $command->getName() === "nick"){
                    if(
    $sender->hasPermission("nick.use")){
                    
    $this->openNickUI($sender);
                }
            } return 
    true;
        }

        function 
    openNickUI($player){
            
    $form = new SimpleForm(function (Player $player$data){
                
    $result $data;
                if(
    $result === null){
                    return 
    true;
                }
                switch (
    $result){
                    case 
    0:
                        break;
                    case 
    1:
                        if(
    $this->getConfig()->get("random-nick") === true){
                            
    $this->randomNick($player);
                        } elseif(
    $this->getConfig()->get("custom-nick") === true){
                            
    $this->openCustomNickUI($player);
                        }
                        break;
                    case 
    2:
                        if(
    $this->getConfig()->get("custom-nick") === true){
                            
    $this->openCustomNickUI($player);
                        }
                }
            });
            
    $form->setTitle($this->getConfig()->get("Main-Title"));
            
    $form->addButton($this->getConfig()->get("Main-Button-Close"));
            if(
    $this->getConfig()->get("random-nick") === true){
                
    $form->addButton($this->getConfig()->get("Main-Button-RandomNick"));
            }
            if(
    $this->getConfig()->get("custom-nick") === true){
                
    $form->addButton($this->getConfig()->get("Main-Button-CustomNick"));
            }
            
    $form->sendToPlayer($player);
            return 
    $form;
        }

        function 
    randomNick(Player $player){
            
    $zahl mt_rand(0count($this->getConfig()->get("random-nicks")) -);
            
    $player->setDisplayName($this->getConfig()->get("random-nicks")[$zahl]);
            
    $player->setNameTag($this->getConfig()->get("random-nicks")[$zahl]);
            
    $message $this->getConfig()->get("nick-set");
            
    $player->sendMessage(str_replace("{nick}"$this->getConfig()->get("random-nicks")[$zahl], $message));
        }

        function 
    openCustomNickUI($player){
            
    $form = new CustomForm(function (Player $player$data){
                if(
    $data[0] === null){
                   return 
    true;
                }
                if(
    $data[0] !== null){
                    
    $config $this->getConfig();
                    
    $config $config->getAll();
                    if(!
    in_array($data[0], $config["not-allow-custom-nicks"])){
                        
    $player->setDisplayName($data[0]);
                        
    $player->setNameTag($data[0]);
                        
    $message $this->getConfig()->get("nick-set");
                        
    $player->sendMessage(str_replace("{nick}"$data[0], $message));
                    } else {
                        
    $player->sendMessage($this->getConfig()->get("not-allowed-nick"));
                    }
                }
            });
            
    $form->setTitle($this->getConfig()->get("CustomNick-Title"));
            
    $form->addInput("Nick""Nick""Nick");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
    }
     
  7. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Because you forgot a closing bracket, the code I sent above has that fixed
     
  8. Adei

    Adei Silverfish

    Messages:
    20
    GitHub:
    Adwin
    it still didnt work herea the updated version

    PHP:
    <?php

    namespace matze;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    jojoe77777\FormAPI;
    use 
    jojoe77777\FormAPI\SimpleForm;
    use 
    jojoe77777\FormAPI\CustomForm;
    use 
    pocketmine\utils\TextFormat as C;

    class 
    nickui extends PluginBase implements Listener{
        function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

          if(
    $command->getName() === "nick"){
        if(
    $sender instanceof Player){
          if(
    $sender->hasPermission("nick.use")){
            
    $this->openNickUI($sender);
          }
        }
      }
      return 
    true;
    }

        function 
    openNickUI($player){
            
    $form = new SimpleForm(function (Player $player$data){
                
    $result $data;
                if(
    $result === null){
                    return 
    true;
                }
                switch (
    $result){
                    case 
    0:
                        break;
                    case 
    1:
                        if(
    $this->getConfig()->get("random-nick") === true){
                            
    $this->randomNick($player);
                        } elseif(
    $this->getConfig()->get("custom-nick") === true){
                            
    $this->openCustomNickUI($player);
                        }
                        break;
                    case 
    2:
                        if(
    $this->getConfig()->get("custom-nick") === true){
                            
    $this->openCustomNickUI($player);
                        }
                }
            });
            
    $form->setTitle($this->getConfig()->get("Main-Title"));
            
    $form->addButton($this->getConfig()->get("Main-Button-Close"));
            if(
    $this->getConfig()->get("random-nick") === true){
                
    $form->addButton($this->getConfig()->get("Main-Button-RandomNick"));
            }
            if(
    $this->getConfig()->get("custom-nick") === true){
                
    $form->addButton($this->getConfig()->get("Main-Button-CustomNick"));
            }
            
    $form->sendToPlayer($player);
            return 
    $form;
        }

        function 
    randomNick(Player $player){
            
    $zahl mt_rand(0count($this->getConfig()->get("random-nicks")) -);
            
    $player->setDisplayName($this->getConfig()->get("random-nicks")[$zahl]);
            
    $player->setNameTag($this->getConfig()->get("random-nicks")[$zahl]);
            
    $message $this->getConfig()->get("nick-set");
            
    $player->sendMessage(str_replace("{nick}"$this->getConfig()->get("random-nicks")[$zahl], $message));
        }

        function 
    openCustomNickUI($player){
            
    $form = new CustomForm(function (Player $player$data){
                if(
    $data[0] === null){
                   return 
    true;
                }
                if(
    $data[0] !== null){
                    
    $config $this->getConfig();
                    
    $config $config->getAll();
                    if(!
    in_array($data[0], $config["not-allow-custom-nicks"])){
                        
    $player->setDisplayName($data[0]);
                        
    $player->setNameTag($data[0]);
                        
    $message $this->getConfig()->get("nick-set");
                        
    $player->sendMessage(str_replace("{nick}"$data[0], $message));
                    } else {
                        
    $player->sendMessage($this->getConfig()->get("not-allowed-nick"));
                    }
                }
            });
            
    $form->setTitle($this->getConfig()->get("CustomNick-Title"));
            
    $form->addInput("Nick""Nick""Nick");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
    }
     
  9. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    Dont say "It doesnt work"
    Post the error message + full code
     
    EdwardHamHam and HimbeersaftLP like this.
  10. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Are you trolling me? You completely missed the onCommand part. Please have at least the most basic understanding of programming before attempting to create a plugin.
     
    EdwardHamHam 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.