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 $player, Command $cmd, string $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; }
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?!!
oh, why are you using permission here!!?? you should use it in command case, not using command case in permission :L
Like this: PHP: //its in command function.//cms is Commandswitch ($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
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.
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.
Thanks for your help. I will mark this thread as Solved. If I need help later, I hope you still want to help me.