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

Solved Unknown Command

Discussion in 'Development' started by KygekDev, Jul 31, 2020.

  1. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    Why when I tried to type "/rules" in the server as a player, it said "Unknown command. Try /help for a list of commands". What's wrong with my code? Can anyone help?

    Project: https://github.com/Kygekraqmak/KygekRulesUI

    plugin.yml:
    Code:
    command:
        rules:
            description: Server rules in UI form
            usage: /rules
            
    permissions:
        rules.command:
            default: true
    Main.php:
    PHP:
    public function onCommand(CommandSender $playerCommand $cmdstring $label, array $args) : bool {
            if(
    $player->hasPermission("rules.command")) {
                if(
    $cmd->getName() == "rules") {
                    if(!
    $player instanceof Player) {
                        
    $player->sendMessage("This command only works in game!");
                    } else {
                        
    $this->kygekRulesUI($player);
                    }
                }
            } else {
                
    $player->sendMessage("You do not have permission to use this command");
            }
            return 
    true;
        }
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    use switch for cmds, its better an easier, also im not in my ide but i think your code in line
    why are you using else for player permission?!!
     
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    oh, why are you using permission here!!??
    you should use it in command case, not using command case in permission :L
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Like this:
    PHP:
    //its in command function.
    //cms is Command
    switch ($cms->getName()) {
    case 
    "rules":
    if (!
    $player->hasPermission("EXAMPLE.PERM")) {
    $player->sendMessage("You dont have permission to use This CMD!");
    } else {
    $this->openRolesUi($player);
    }
    return;
    break;
    // case 2


    //case 3

    //and more :)

    return 
    true;
    }

    }
    im not in my ide, pls test if it has error tag me here :)
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    The problem is in the plugin.yml instead of 'command' key use plural form 'commands'.
    Code:
    commands:
       rules:
           description: Server rules in UI form
           permission: rules.command
           usage: /rules
    
    If you specify the permission in command registration then you don't have to worry about checking them.
     
  6. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    How to add permission defaults (true/op/false) then?
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    You have done it right.
    Code:
    true: everyone can use it
    false: no one can use it
    op: only operators can use it
    notop: everyone except operators can use it
    
    By passing the registered permission node to command, it will take the 'default' value from permission itself. You don't have to second specify it in commands.

    You could had save yourself some time just by looking at how others have done it.
     
    Diduhless likes this.
  8. KygekDev

    KygekDev Witch

    Messages:
    72
    GitHub:
    KygekDev
    Thanks for your help. I will mark this thread as Solved. If I need help later, I hope you still want to help me.
     
    Primus 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.