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

Solved Custom message for no-permission not working

Discussion in 'Development' started by AlexSima, Jul 4, 2020.

  1. AlexSima

    AlexSima Spider Jockey

    Messages:
    38
    GitHub:
    AlexSima003
    PHP:
    $username onCommand($player->getName());
                if(
    $command->getName() == "pui"){
                    if(!(
    $player instanceof Player)){
                            
    $player->sendMessage("No u dont have permission");
                            return 
    false;
    Its not working, the message is still default..
    How do i fix this?
     
    Last edited: Jul 4, 2020
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    If you return false it will show the default usage message, return true instead
    PHP:
    $username onCommand($player->getName());
    This line doesnt look right too
     
  3. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    did you set permission in plugin.yml for command ? if yes you just need to unset it from plugin.yml and done . you should use === for if($command->getName() == "pui"){ Cuz command's name is string and == is for bool - int - float &... but for string you should use ===
     
  4. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    and this code is trash . you just say if the sender is isntanceof Player . you didnt set any permission for the command . start learning from basics
     
  5. AlexSima

    AlexSima Spider Jockey

    Messages:
    38
    GitHub:
    AlexSima003
    I added === still didnt work
    I removed permissions from plugin.yml now everyone can use the command..
     
  6. AlexSima

    AlexSima Spider Jockey

    Messages:
    38
    GitHub:
    AlexSima003
    I change it to return true, still not working
    I asked for help, not for opinions..
     
  7. AlexSima

    AlexSima Spider Jockey

    Messages:
    38
    GitHub:
    AlexSima003
    Self solved!
    For those who are looking:
    PHP:
    public function onCommand(CommandSender $playerCommand $commandstring $label, array $params) : bool
        
    {
        
    $name $player->getName();
            if(!
    $player instanceof Player){
            
    $player->sendMessage("Please use command in-game");
            return 
    false;
            }
                
    $username strtolower($player->getName());
                if(
    $command->getName() === "pui"){
                    if(!
    $player->hasPermission("p.ui")){
                            
    $player->sendMessage("§7You don't have permission");
                            return 
    true;
                    }
    Permissions from plugin.yml have to be removed.
     
  8. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    thats what i told you thats not self sloved but gg
     
  9. AlexSima

    AlexSima Spider Jockey

    Messages:
    38
    GitHub:
    AlexSima003
    All u told me was to delete permissions from plugin.yml and add ===, u didnt help me at all, i found another post like mine and i saw there how to do it..
     
  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.