plugin.yml permissions/command args permissions

Discussion in 'Plugin Development' started by MCCoding, May 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MCCoding

    I'm have a command that uses several different arguments for multiple outcomes, i have a base command /p and lots of args on that command for example /p reload and /p stop. but how would i allow different permission nodes on the sub commands? what i have now is one permission node that allows you to use the /p command it's command.p and several permission nodes for the /p reload like command.p.reload which what is happening now is if you have the permission command.p and don't have the permission for the other args it will still allow you to run the command. Here is my code:

    Code:java
    1. if (args.length == 0) {
    2. if(sender.hasPermission("command.p")) {
    3. sender.sendMessage("Testing");
    4. return true;
    5. }
    6. }
    7.  
    8. if(args.length == 1) {
    9. if(sender.hasPermission("command.p.reload")) {
    10. if(args[0].equalsIgnoreCase("reload") ) {
    11. sender.sendMessage("Testing length 2");
    12. }
    13. }
    14. }
     
  2. Offline

    ShadowWizardMC

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    2. Player player = (Player) sender;
    3. if(cmd.getName().equalsIgnoreCase("YOURcommand") && args.length == 0){
    4. if(player.hasPermission("your.permission"));
    5. // Do stuff here
    6. }
    7. if(cmd.getName().equalsIgnoreCase("YOURcommand") && args.length == 1 && args[0].equalsIgnoreCase("subcommand")){
    8. if(player.hasPermission("subcommand.permission"));
    9. // Do stuff here
    10. }
    11. }


    MCCoding Contuniue copy pasting the sub command part and make sure and use/fix your brackets properly.
     
Thread Status:
Not open for further replies.

Share This Page